Switching Versions Of Grails (and other tools)
Posted by:
Jeff Brown
on 04/23/2010
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 Grails. 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?".
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...
One thing I might do when I need to use a specific version of Grails is something like this...
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.
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.
Moving the symlink is easy enough but I simplify it further by defining aliases in my ~/.profile. Those look something like this...
Now if I want to use Grails 1.2.2 I just open a shell and type "gr122".
I use the exact same approach for other tools that I may want to easily move from version to version.
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.
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.
Enjoy!
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...
grails-1.0.5
grails-1.1.1
grails-1.1.2
grails-1.2-M4
grails-1.2.0
grails-1.2.0.RC1
grails-1.2.0.RC2
grails-1.2.1
grails-1.2.2
grails-1.3.0.RC1
grails-1.3.0.RC2
One thing I might do when I need to use a specific version of Grails is something like this...
export GRAILS_HOME=~/Tools/grails-1.2.2
export PATH=$GRAILS_HOME/bin:$PATH
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.
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.
Moving the symlink is easy enough but I simplify it further by defining aliases in my ~/.profile. Those look something like this...
alias gr105='rm ~/Tools/grails && ln -s ~/Tools/grails-1.0.5 ~/Tools/grails'
alias gr111='rm ~/Tools/grails && ln -s ~/Tools/grails-1.1.1 ~/Tools/grails'
alias gr112='rm ~/Tools/grails && ln -s ~/Tools/grails-1.1.2 ~/Tools/grails'
alias gr12='rm ~/Tools/grails && ln -s ~/Tools/grails-1.2.0 ~/Tools/grails'
alias gr121='rm ~/Tools/grails && ln -s ~/Tools/grails-1.2.1 ~/Tools/grails'
alias gr122='rm ~/Tools/grails && ln -s ~/Tools/grails-1.2.2 ~/Tools/grails'
alias gr130rc1='rm ~/Tools/grails && ln -s ~/Tools/grails-1.3.0.RC1 ~/Tools/grails'
alias gr130rc2='rm ~/Tools/grails && ln -s ~/Tools/grails-1.3.0.RC2 ~/Tools/grails'
# use my local development copy of Grails
alias grdev='rm ~/Tools/grails && ln -s /Users/jeff/Projects/grails/core ~/Tools/grails'
Now if I want to use Grails 1.2.2 I just open a shell and type "gr122".
I use the exact same approach for other tools that I may want to easily move from version to version.
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.
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.
Enjoy!
Jeff Brown's complete blog can be found at: http://javajeff.blogspot.com
About Jeff Brown
Core member of the Grails development team, Jeff Brown, is a Senior Software Engineer with SpringSource. Jeff has been involved in designing and building object oriented systems for over 15 years. Jeff's areas of expertise include web development with Groovy & Grails, Java and agile development.
More About Jeff »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 7
- Agility
- Testing: Geb, Spock, Easyb
- REST
- NoSQL: MongoDB, Cassandra
- Hadoop
- Spring 3
- Automation Tools: Git, Hudson, Sonar
- HTML5, Ajax, jQuery, Usability
- Mobile Applications - iPhone and Android
- More...
NFJS, the Magazine
May Issue Now AvailableClient-Side MVC with Spine.js, Part 1
by Craig WallsOn Prototypal Inheritance, Part 2
by Raju GandhiMaking use of Scala Lazy Collections
by Venkat SubramaniamIntegration Testing Web Applications Using Gradle
by Kenneth Kousen


