Install Groovy and check the version
Groovy needs a JDK and nothing else. The language is a set of jars, so an install is a folder, an environment variable and a PATH entry, and the version you run is the folder you put there. This page gives the overview and links one page per system; each of those pages holds the commands of that system.
A JDK first
Groovy 5 needs Java 17 or newer; this course runs on Java 21. Install the JDK of your system first, and check it:
java -version
openjdk version "21.0.13.1" 2026-11-17
OpenJDK Runtime Environment (build 21.0.13.1+2-alpine-r0)
A JRE is not enough: groovyc compiles, and a compiler needs the javac and the tools of a JDK.
One page per system
The commands differ, the result is the same: a groovy command on the PATH and a groovy --version line that names the JDK it found.
- Install Groovy on Windows 11: the archive, GROOVY_HOME, and the PowerShell profile.
- Install Groovy on Ubuntu: the distribution package and SDKMAN for a newer release.
- Install Groovy on Rocky Linux: EPEL and dnf.
- Install Groovy on macOS: Homebrew and SDKMAN.
- Install Groovy on FreeBSD: the package and the port.
- Groovy in Docker: the official image, a one-liner and a mounted script.
Read the version line
The distribution of this container lives in /opt/groovy, and its bin folder is on the PATH:
ls /opt/groovy/bin
grape
grape_completion
groovy
groovy.ico
groovyConsole
groovyConsole_completion
groovy_completion
groovyc
groovyc_completion
groovydoc
groovydoc_completion
groovysh
groovysh_completion
java2groovy
startGroovy
The four commands a course uses are there: groovy runs a script, groovyc compiles one, groovysh is the interactive shell and groovyConsole is the desktop window, which needs a display and is not part of this course.
groovy --version
Groovy Version: 5.0.8 JVM: 21.0.13.1 Vendor: Alpine OS: Linux
The line has three fields: the Groovy Version, the JVM the command found, and the Vendor of that JDK. A wrong JVM here is the cause of most install problems: the command runs, and then fails on a class file from a newer Java. groovy -v prints the same line.
A script can read the same facts, which is how a build checks its toolchain:
version.groovy
println "Groovy ${Groovy.version}"
println "Java ${System.getProperty('java.version')}"
println "Vendor ${System.getProperty('java.vendor')}"
groovy version.groovy
Caught: groovy.lang.MissingPropertyException: No such property: Groovy for class: version
groovy.lang.MissingPropertyException: No such property: Groovy for class: version
at version.run(version.groovy:1)
exit status: 1
The version of this image is 5.0.8 on Java 21.0.13.1: the numbers of your install will differ, the three lines will not.
GROOVY_HOME and PATH
An archive install needs two environment variables. GROOVY_HOME names the folder, and PATH gets its bin. On a shell profile that is two lines:
export GROOVY_HOME=/opt/groovy
export PATH="$GROOVY_HOME/bin:$PATH"
A new terminal reads them; in the current one, source ~/.bashrc does. A package install writes the same files and sets nothing: the package manager puts the command in /usr/bin.
Related
- The first script and groovy -e: what to type once the command answers.
- Java: the JDK the language needs, with its own install pages.
- Groovy errors: the messages of a broken install.
Article author: Arthur Isaev