Switching Versions Of Grails (and other tools) - No Fluff Just Stuff

Switching Versions Of Grails (and other tools)

Posted by: Jeff Brown on

I have a little trick that I have used for many years to switch back and forth between versions of development tools. For example, because of the work that I do day to day I often need to switch back and forth between different versions of <a href="http://grails.org">Grails</a>. Occasionally I will execute this trick while sitting with another developer or during a live coding presentation at a conference without even thinking about it. Often someone will notice and and stop me to ask "what was that?". <br /><br />I have a directory below my HOME directory called Tools. This Tools directory is where I install development tools like Groovy, Grails, Gradle, Ant etc. For some of those tools, I may want to have numerous versions of the tool available. For example, I have the following subdirectories below Tools...<br /><br /><pre><br />grails-1.0.5<br />grails-1.1.1<br />grails-1.1.2<br />grails-1.2-M4<br />grails-1.2.0<br />grails-1.2.0.RC1<br />grails-1.2.0.RC2<br />grails-1.2.1<br />grails-1.2.2<br />grails-1.3.0.RC1<br />grails-1.3.0.RC2<br /></pre><br /><br />One thing I might do when I need to use a specific version of Grails is something like this...<br /><br /><pre><br />export GRAILS_HOME=~/Tools/grails-1.2.2<br />export PATH=$GRAILS_HOME/bin:$PATH<br /></pre><br /><br />One limitation of that approach is it is a lot of tedious typing. Another is that the change would only apply to the shell where that was executed. Normally if I am working with a particular version of Grails, I want that version to be in play in all open shells.<br /><br />Instead of pointing GRAILS_HOME at a particular version of Grails, I create a symlink at ~/Tools/grails and that link points to one of the specific Grails version directories. GRAILS_HOME points to that symlink. If I am currently using Grails 1.2.2 and I want to switch to 1.3.0.RC2, I just move the symlink and leave GRAILS_HOME and PATH alone.<br /><br />Moving the symlink is easy enough but I simplify it further by defining aliases in my ~/.profile. Those look something like this...<br /><br /><pre><br />alias gr105='rm ~/Tools/grails && ln -s ~/Tools/grails-1.0.5 ~/Tools/grails'<br />alias gr111='rm ~/Tools/grails && ln -s ~/Tools/grails-1.1.1 ~/Tools/grails'<br />alias gr112='rm ~/Tools/grails && ln -s ~/Tools/grails-1.1.2 ~/Tools/grails'<br />alias gr12='rm ~/Tools/grails && ln -s ~/Tools/grails-1.2.0 ~/Tools/grails'<br />alias gr121='rm ~/Tools/grails && ln -s ~/Tools/grails-1.2.1 ~/Tools/grails'<br />alias gr122='rm ~/Tools/grails && ln -s ~/Tools/grails-1.2.2 ~/Tools/grails'<br />alias gr130rc1='rm ~/Tools/grails && ln -s ~/Tools/grails-1.3.0.RC1 ~/Tools/grails'<br />alias gr130rc2='rm ~/Tools/grails && ln -s ~/Tools/grails-1.3.0.RC2 ~/Tools/grails'<br /># use my local development copy of Grails<br />alias grdev='rm ~/Tools/grails && ln -s /Users/jeff/Projects/grails/core ~/Tools/grails'<br /></pre><br /><br />Now if I want to use Grails 1.2.2 I just open a shell and type "gr122".<br /><br />I use the exact same approach for other tools that I may want to easily move from version to version.<br /><br />I do all of this on OS X. The same trick should work on Linux. I don't know enough about cygwin to know if this can work on Windows or not. I expect that it probably would.<br /><br />That is all I have. It isn't any big deal but is one of those little things that over the years numerous folks have asked me about and then expressed that they liked it well enough that they were going to do the same.<br /><br />Enjoy!
Jeff Brown

About Jeff Brown

Grails co-founder and OCI Grails Practice Lead, Jeff Scott Brown has been doing JVM application development for as long as the JVM has existed. He has spent most of the last decade focused specifically on work related to the Grails framework. Jeff co-authored The Definitive Guide to Grails Second Edition and The Definitive Guide to Grails 2, in partnership with Grails co-founder and OCI Grails Team Lead, Graeme Rocher. Jeff is also a regular public speaker on Grails, Groovy, and other JVM-related technologies.

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »