Groovy & Grails: Installing Groovy and the JDK
What You Need
Both Groovy and Grails run on the Java Virtual Machine, so the JDK comes first. Use a recent Long Term Support release like JDK 17 or 21. After the JDK is installed, verify it in a terminal, then install Groovy, then install the Grails command line tool.
java -version
groovy -version
grails -versionEach command should print a version line. This quick sanity check confirms the tools are on your PATH and can see each other.
Installing on Windows, macOS, and Linux
The cleanest route on macOS and Linux is a package manager such as Homebrew, SDKMAN, or the distribution package manager. Windows users can use Chocolatey or scoop, or download the archives manually.
# macOS with Homebrew
brew install groovy grails
# JVM environments with SDKMAN
sdk install java 17-open
sdk install groovy
sdk install grailsPackage managers handle PATH configuration and updates for you. If you download archives instead, unzip them and point the PATH variable at the bin folders.
First Script
Save a file called hello.groovy with a single line and run it.
println "Hello from Groovy"Then execute groovy hello.groovy in the terminal. There is no class, no main method, and no compile step; the script just runs. This immediacy is what makes Groovy friendly for automation and quick experiments.
Troubleshooting
- Command not found means the bin folder is not on PATH.
- A Java error means JAVA_HOME is unset or points at an old JDK.
- Grails uses a lot of memory, so allow the default heap settings.
- Restart the terminal after changing PATH or JAVA_HOME.
With all three tools reporting their versions, you are ready to write Groovy scripts and generate your first Grails application.
Key Points
- Install a recent JDK first, since Groovy and Grails run on the JVM.
- Package managers like SDKMAN or Homebrew make installation painless.
- Verify with java -version, groovy -version, and grails -version.
- A single println script proves the toolchain works end to end.