Tuesday 18 March 2008

Groovy on Mac OS X Leopard

Groovy is the new "Ruby" like language that runs on top of the Java VM, it is the backbone of the Grails initiative which aims to provide a Rails like environment on the Java Platform, Groovy is to Grails, as Ruby is to Rails. 

This post will show you how to setup groovy on Leopard, and allow you to explore this intriguing new language.

Prerequisites

First make sure you have java and its dev tools setup on your machine see this post on how to do that

Now download groovy from the groovy site. 

Unpack the archive and move it to /usr/share , for example:
$ sudo mv ~/downloads/groovy-1.5.4 /usr/share 
Now set ownership and permissions on the directories
$cd /usr/share
$sudo chown -R root:wheel groovy-1.5.4/
$sudo chmod 0755 groovy-1.5.4/bin/*
Now create a symlink to access the current version of groovy by, if you download and install another version later, you can just move the symlink to point at it, this is a good practice as it prevents you having to overwrite your old installation.
$sudo ln -s groovy-1.5.4 groovy
Finaly add the following to your /etc/profile or ~/.profile depending on wether you want it available for all logons or just your own. 
GROOVY_HOME=/usr/share/groovy; export GROOVY_HOME
And the following to your path in the same file, note your path should be defined after the above
PATH=$GROOVY_HOME/bin:$PATH; export PATH
Now your ready to try it out and see if it works, open up a terminal and type:
$groovyConsole
The groovy console window should open up as shown above, thats it your done, stay tuned for more groovy news.

15 comments:

Jeff said...

Thanks, your install instructions worked great for me.
Just 2 changes:
I needed sudo before $ln -s groovy-1.5.4 groovy
Path statement has spaces around the =
It should be:
PATH=$GROOVY_HOME/bin:$PATH; export PATH

Michał Huniewicz said...

Thanks a lot, very helpful. :)
Michal Huniewicz

Unknown said...

This was just what I was looking for. Thanks for the great instructions for Groovy and also Java. Now on to Grails!

Daniel Shaw said...

Thanks Tim. This helped a lot. I hate configuring PATH variables.

One note to the less command line l337 like myself: to test the Groovy Console type "groovyConsole" instead of "$groovyConsole". The dollar sign represents the command prompt again. I got confused after typing the PATH variables.

Grant said...

Just wanted to say thank you. This worked for me exactly as written (although I did change the install directory and used groovy 1.6. Thank you for taking the time to write this!

-Grant Gortsema

All night long ! said...

Installed 1.6.4 worked like charm
thanks
BTW i used ~/.bash_profile instead of whatever ...

thanks again

Unknown said...

Thanks! Worked fine for 1.7.1 on snow leopard.

Anonymous said...

Working Great on Snow Leopard 10.6.4 MBP

Helpful for a script-er going to java! :)

Thanks!

Anonymous said...

On the Mac -unless you want to install version 1.7- it's easier to use Ports:

$ sudo port install groovy

Same story with Grails.

Anonymous said...

Thanks very much! That was much faster than downloading XCode, required to install MacPorts... Happy New Year!

puchu said...

Awesome....Thank you very much!

Unknown said...

Thanks for the info. I installed 1.8.5 and it worked great. I learned a little about the Unix command line too

Jason Stonebraker said...
This comment has been removed by the author.
Anonymous said...

Just wanted to say thanks for this post. I've referred to it multiple times over the past week for various installations (not just Groovy). Very helpful... Thanks!

Claire said...

Thanks for the straightforward and comprehensive instructions (especially the direction to put it in /usr/share - I never seem to work out the best place to put these packages).