Installing a Grails Development Environment on OS X


Updated for Grails 2.3.x
Video #4: In this Grails Example, we will set up our development environment on an OS X environment.

This first video shows you how to install Grails and Java on OS X. To install Grails, you will need a Java Developers Kit (www.apple.com), and the Grails libraries (www.grails.org). This video will show you how to download and install both. We will be using the Groovy Environment Manager (GVM) to easily install the latest version of Grails.

Subscribe to Grails Academy Magazine.

Video #5: In the second video, you learn how to install an Integrated Development Environment (IDE) based on Eclipse called the Groovy/Grails Tool Suite. This tool is pre-configured for Groovy and Grails to give you features such as syntax highlighting and code completion. The video shows you how to install it and configure it for the Grails 2.1.1 environment that you installed in the previous video.

53 thoughts on “Installing a Grails Development Environment on OS X

  1. I remember, back on my first time on osx / linux, having a hard time figuring out how bash_profile or bashrc or profile was working…

    NOW, I know how it work, and I think it is very important to know HOW and HOW it work…

    NIce tutorial, cant wait to make some development with Grails

    thanks :)

  2. Nice vid, though a bit long/unnecessary for anyone who’s done any kind of programming before. Here are the Cliff’s notes:

    Install a JDK
    $ java -version # make sure it works

    Download/install GVM:
    $ curl -s get.gvmtool.net | bash
    $ source ~/.gvm/bin/gvm-init.sh

    Install Grails using GVM:
    $ gvm install grails
    $ grails -version # make sure it works

    Check environment for GRAILS_HOME and JAVA_HOME
    $ printenv | grep HOME

    Make a test project:
    $ mkdir grails; cd grails
    $ grails create-app test-proj

    Run the test app:
    $ grails run-app

    Should result in:
    “Server running. Browse to http://localhost:8080/test-proj

  3. Great tutorial. In case it’s helpful to others, thought I’d comment about a couple of issues I encountered on Mavericks, Grails v2.4.0, Java v1.7.0_51 when building the app in GGTS.

    First I got a mismatch error about the project level being different from the workspace level. This can be fixed by right-clicking on the project folder, then Properties > Groovy compiler and selecting the correct compiler level (21, in my case).

    Second error: “objc[8368]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.” This came up when I ran the app via command line, but it proceeded to launch without causing any more problems so I thought nothing of it at the time. According to a few posts on StackOverflow it’s a bug in the JDK that Oracle are taking their time in fixing. So, in GGTS, you have to tell it to proceed despite this error and just put up with its annoying persistence :)

  4. Hey, Mike,

    I have installed all the latest components on my Mac as per the videos, Except when running GVM to install Grails, it doesn’t put it in my grails dir, it puts it in a .gvm dir off my root. I didn’t think that was a problem as, I just pointed my grails environment in GGTS to point to that installation.

    When I try to run the test app, I get this:

    An internal error occurred during: “Launching test: run-app”.
    java.lang.NullPointerException
    —–
    I’m running:
    Mac OSX 10.9.2
    JAVA 1.6.0_32
    Grails 2.3.8
    GGTS 3.5.0

    Any thoughts? Checking my environment variables, it seems that everything is “correct”, but I’m a bit stuck.

    Thanx,

    Brad

    • Followup – I created a Java project in GGTS, did a simple hello world app, and it all came up just fine. Still can’t get my grails project to work. Thanks.

      • Hi Brad:
        I haven’t done an OS X install with all the new tools yet, but a good way to check if GVM set everything up correctly is to open a terminal, and set your current directory to somewhere that is not where Grails or Java is installed. Then execute the following:
        java -version
        javac -version
        grails -version

        if all three come back without errors, then your jvm, jdk, and grails environments are correct. If GGTS allowed you to create a new Grails project, I’m thinking everything is set up correctly there as well. It may be a new issue with either Grails or GGTS. There is a lot of good discussion on stackoverflow.com, and someone may have come across this as well. I’ll try this on a virtual OS X machine and see how it works for me.

        ~Mike

        • Yep. Already tried that, and the version calls all came back correctly. I’ll check on StackOverflow. It’s weird. I’ve never seen it before. This was a fresh install after a hard drive failure. Something isn’t “clean”, but I’m not sure what. I’ll keep looking.

  5. Any advice on this particular error?

    | Compiling 143 source files.
    | Error Compilation error: startup failed:
    /Users/okcomputer/grailsapps/demo/target/work/plugins/database-migration-1.3.8/grails-app/controllers/grails/plugin/databasemigration/DbdocController.groovy: -1: Repetitive method name/signature for method ‘java.lang.Object withFormat(groovy.lang.Closure)’ in class ‘grails.plugin.databasemigration.DbdocController’.
    @ line -1, column -1.
    /Users/okcomputer/grailsapps/demo/target/work/plugins/database-migration-1.3.8/grails-app/controllers/grails/plugin/databasemigration/DbdocController.groovy: -1: Repetitive method name/signature for method ‘java.lang.Object withFormat(groovy.lang.Closure)’ in class ‘grails.plugin.databasemigration.DbdocController’.
    @ line -1, column -1.
    2 errors
    okcomputer@thegibson:~/grailsapps/demo$

    As far as i can tell its some kind of DB error, but this is my first attempt installing grails. Also, this is Java8 on osx10.9, should I revert to java 7 or 6 and try again?
    Thanks

    • Yes, the first thing I would do is downgrade Java. I have had may problems with incompatible Java versions on OSX. I have been most successful with the version that auto-installs when you enter a Java command at the terminal. If the auto install no longer triggers, get the most current version from the support page on apple.com.

    • Just another follow-up on this. Grails 2.3 will not run under Java 8 on any platform. Java 8 will not work with Grails until 2.4 is released.
      ~Mike

  6. When I try to configure Grails installation under users/username/grails/grails_app I received the message: Specified directory does not appear to be a Grails installation.

    • Alice – which Grails command caused you to get that error? It looks like the create-app command did not succeed as it is not seeing a grails application in that subdirectory.

  7. Thank you for the excellent video on installing Grails on OS X. I viewed the video to verify my grails installation which is exactly the same as shown, except I am using Grails 2.3.5. I am baffled because when I run the demo application, I see the “Error generating web.xml file” message rather than the “Server running” as shown in the video.

    I have searched the web and found nothing helpful. Is this error message due to a configuration issue? Or is it a Tomcat bug, as the stack trace shows…
    org.apache.xml.serializer.utils.WrappedRuntimeException: org.apache.xml.serializer.ToXMLSAXHandler cannot be cast to org.apache.xml.serializer.SerializationHandler

    Or, could it be that my MacBook with 4Gb memory is insufficient to run Grails?
    I am clueless….Thanks.

    • Hi Tom:

      I’ve had issues on the Mac with Java. I have found that installing the latest version of Oracle Java 6 works best with Grails as opposed to Java 7. 4GB of RAM should be plenty.

      Mike

  8. i am installing grails through this video
    i have done till export window and then :wq
    closed that terminal
    opened up a new to check the version as per your video
    the java -version is working and giving me the appropriate version
    but grails -version is not working.. it says grails command not found
    whats the issue now ?

  9. hola, excelente video! gracias por la aportación, podrias hacerlo en español o con subtítulos por que no le entiendo muy bien… cuando haces el grails-2.2.2 y enseña a configurarlo con mysql por favor

  10. Just in case you were curious, vim is Vi iMproved. Its an extended version of VI, runs the same commands, but has slight modifications to it.

  11. Very nice, thank you. But, I wouldn’t set GRAILS_HOME in the .bash_profile to a specific grails version. Instead I would create a soft link in the grails directory that points to the current used version of grails, like this:

    ln -s /users//grails/grails-2.2.0 /users//grails/grails

    The main advantage is, in case of a new grails version, you only need to update the soft link and don’t need to update your .bash_profile or other files.

  12. Love your videos. I tried installing Groovy/Grails Tools Suite (Version: 3.1.0.RELEASE
    Build Id: 201210061306) on Mac OS X 10.6.8(not Mountain Lion) but keep getting this error:
    Error Error loading plugin manager: Could not create a new instance of class [ResourcesGrailsPlugin]! (Use –stacktrace to see the full trace)

    any ideas??
    Thanks

  13. Love the video. I was wondering if you have to have Mountain Lion to run the newer version of Grails. I am running on Snow Leopard (yea I am behind) and when I follow the video exactly and type “grails -version” in my terminal, I get “command not found”.

    • My first videos were on Snow Lion and it worked fine. The message you are getting is because your path must not be set up. Try to change directories into the bin directory under where Grails is installed. If the commands work there, you just need to add the path to your profile. I think OS X stores the bash profile in a different place than Mountain Lion though.

  14. my mac does not show whether its 32 bit or 64 bit… at least not the you showed in the video…

    System Software Overview:

    System Version: OS X 10.8 (12A269)
    Kernel Version: Darwin 12.0.0
    Boot Volume: Macintosh HD
    Boot Mode: Normal
    Computer Name: Vikram’s Mac mini
    User Name: Shantanu Nanoty (snanoty)
    Secure Virtual Memory: Enabled
    Time since boot: 5:13
    this is what is displayed..

    • Thanks for the input. I just updated the videos for Grails 2.1 and include that now. Also, if you are following the course and stay in the Eclipse environment, the IDE takes care of those.

  15. Howdy. Very nice website!! Man .. Excellent .. Amazing .. I’ll bookmark your website and take the feeds additionally…I’m glad to find so much useful information here in the post. Thank you for sharing..

  16. Excuse me, but I attempted to email you regarding an issue on your site but the given email address did not work. Is there some other place I could get in touch with you?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>