Using RVM Gemsets

106 11
One of the most powerful, useful and often overlooked features of RVM is the gemset. A gemset is a separate gem directory, so the gems in one gemset don't conflict with the gems in another gemset. A common usage would be to install Rails 2 in one gemset, and Rails 3 in another. Since they're in different gemsets, there's no possibility of them interfering with each other.

Using gemsets is easy. First, switch to the interpreter you want to create gemsets on.


I'll be switching to 1.8.7. Next, just use the rvm gemset create command, along with a descriptive name for the gemset. I'll be creating a gemset for both Rails 2 and Rails 3.
$ rvm use 1.8.7

info: Using ruby 1.8.7 p174
$ rvm gemset create rails2

info: Gemset 'rails2' created.
$ rvm gemset create rails3

info: Gemset 'rails3' created.

Once those are created, do a rvm gemset list command to see what gemsets there are. If you have a lot of gemsets, or forget what you named them, this will show you what gemsets are available to use. You'll also see a gemset called global. The global gemset is the gemset used if you don't specify any other gemset to use.
$ rvm gemset list

info: gemsets : for ruby-1.8.7-p174 (found in /home/user/.rvm/gems/)
global
rails2
rails3

To switch to a gemset, use the rvm gemset use command. Once you're using a gemset, any gem
$ rvm gemset use rails2

info: Now using gemset 'rails2'

After switching to the rails2 gemset, you could issue a standard gem command such as gem install rails to install Ruby on Rails version 2.

Once that's finished, you can issue the command rvm gemset use rails3 to switch to the rails3 gemset, then a different gem command such as gem install --pre rails to install Ruby on Rails version 3 into the rails3 gemset. You can now easily switch between Ruby on Rails version 2 and 3 without having to worry about them conflicting, requiring different versions of dependencies, etc.

If something goes horribly wrong with Rails 3 (it's pre-release at the time of this writing, so that could happen), you can just wipe out your rails3 gemset and start again. Doing this is very easy, simply delete the gemset with the rvm gemset delete rails3 command. Note that this will delete the gemset, as well as all the gems inside of it. You might want to list the gems you have installed for future reference, which you can do with the gem list command. After it's deleted, create it again as before and re-install you gems.

More information about Gemsets can be found at here. A lot more is possible, including copying gemsets, exporting and importing them, etc.
Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.