Installing Grails on OS X 10.6

Grails is an excellent rapid application development framework that integrates well with many industrial-strength analytics products.

Here’s how to install Grails 1.3.7 on Mac OS X 10.6 Snow Leopard.  It should also work on earlier versions of Grails and OS X. I will note that Grails.org does provide instructions, but I prefer these.

Install Java SDK

Before you install Grails, 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 Grails

Download Grails from grails.org.

Install Grails

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/grails-1.3.7/usr/share/java

Note:  some people install it to /usr/share/, but these instructions install it to /usr/share/java because that’s where other Java tools like Maven, Ant, JUnit and Derby are installed. Grails’ official instructions suggest your home directory (~/grails), which is just plain weird.

Change ownership and permissions:

$cd /usr/share/java
$sudo chown -R root:wheel grails-1.3.7/
$sudo chmod 0755 grails-1.3.7/bin/*

Create a symlink that allows you to access Grails without referencing the version number.  This way, to upgrade your Grails you just install the newer version alongside the old one, and update this symlink.  This is a standard best practice.

$sudo ln -s grails-1.3.7 grails

To make Grails available, add the following either to /etc/profile (for everyone) or ~/.profile (for just you):

export GRAILS_HOME=/usr/share/java/grails
export PATH=$GRAILS_HOME/bin:$PATH

If you haven’t set the JAVA_HOME environment variable yet, create one in .profile that points to the path where you have installed Java. It’ll be something like this.

export JAVA_HOME=/Library/Java/Home

Let’s see if it works. Open Terminal and type:

$grails

You should see:

Welcome to Grails 1.3.7 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /usr/share/java/grails
No script name specified. Use 'grails help' for more info or 'grails interactive' to enter interactive mode

Happy Grailing!

  • Pingback: grailstutorial.org()

  • Thanks for the write-up!

    After following your instructions, I can launch grails with a “sudo grails” command, but grails by itself gives an error that seems to arise from groovy…

    java.lang.SecurityException: Prohibited package name: java.lang
    at java.lang.ClassLoader.preDefineClass(ClassLoader.java:480)
    … (long call stack)…
    at org.codehaus.groovy.grails.cli.support.GrailsStarter.rootLoader(GrailsStarter.java:221)
    at org.codehaus.groovy.grails.cli.support.GrailsStarter.main(GrailsStarter.java:262)

    I set the permissions as you described. Any thoughts what might be wrong?

    • Dean Moses

      Daniel, I suspect you have some jar in your classpath (like rt.jar) that contains a duplicate java.lang package. There could be several things that cause this. The comments on this ticket at Codehouse lists several places where it might happen: http://jira.codehaus.org/browse/GROOVY-1386

      Good luck!

  • terrific instructions! Worked immediately.

  • whoops, a tiny bit too quick.
    When I tried grails create-app it failed saying that it couldn’t write the app. I committed some form of malpractice or suicide by opening up privileges (through Info on the java folder) and it worked.

  • Thanks for the quick tutorial, very helpful.

    • Thanks for writing such an easy-to-undesrtand article on this topic.