Groovy is an agile, dynamic language for the Java platform. It has the speed and flexibility of Ruby but it compiles down to Java bytecode. It’s the foundation of the Grails framework.
Here’s how to install Groovy 1.7.9 on Mac OS X 10.6 Snow Leopard. It should also work on earlier versions of Groovy and OS X. I will note that Groovy does provide instructions, but I prefer these. There’s also a MacPorts installer, but I never have any luck with MacPorts.
Install Java SDK
Before you install Groovy, make sure you have a Java SDK 1.5+ installed. The Java runtime that comes preinstalled with OS X does not have the SDK.
Download Groovy
Download Groovy from groovy.codehaus.org.
Install Groovy
Unpack the archive you downloaded. It’ll be a folder.
Move the folder to /usr/share/java. I just used Finder, but here’s the obligatory Terminal command:
$ sudo mv ~/downloads/groovy-1.7.9/usr/share/java
Create a symlink that allows you to access Groovy without referencing the version number. This way, to upgrade your Groovy you just install the newer version alongside the old one, and update this symlink. This is a standard best practice.
$sudo ln -s groovy-1.7.9 groovy
To make Groovy available, add the following either to /etc/profile (for everyone) or ~/.profile (for just you):
export GROOVY_HOME=/usr/share/java/groovy export PATH=$GROOVY_HOME/bin:$PATH
If you haven’t set the JAVA_HOME environment variable yet, create one in .profile that points to the path where Java’s installed. It’ll be something like this.
export JAVA_HOME=/Library/Java/Home
Let’s see if it works. Open Terminal and type:
$groovy
You should see:
Groovy Shell (1.7.9, JVM: 1.6.0_24) Type 'help' or '\h' for help. ------------------------------------------------------------ groovy:000>
This is Groovy’s interactive command shell. Hit Ctrl-C to exit.
Now go get yer Groov on!