As the Ruby community begins to transition to Ruby 1.9 as the standard, there are some things that I needed to address. This weekend, Arch Linux migrated to ruby version 1.9 in the upstream repositories. I’m a big fan of running bleeding edge software releases, so Arch works well… I would have hoped that the upgrade to 1.9 would be seamless, but there are a few issues that would compel me to run multiple versions of Ruby happily on the same machine, namely:
- Not all gems and plugins have updated to be compatible with 1.9
- Older projects that will not be upgrading to the latest release are still required
- Duplicating production environments as closey as possible
Meet rvm. It provides the tools necessary to have multiple versions of Ruby installed at the same time, and mechanisms to switch quickly and painlessly between them without jumping through any hoops.
Fire up a terminal and:
rvm-install will walk you through a series of prompts to finish the install. Most importantly, it will ask you about installing some hooks into your bash/zsh config files. This adds some of the rvm tools to your PATH. Once that is complete, logout of your current shell and log back in, you should now be able to do something like this:
This output will tell you some of the details of the current version of Ruby you’re running. My system has 1.9.1 installed, but what if I have an application or package that needs 1.8.6 to run properly?
installing another version of ruby
If I want to install version 1.8.6 of Ruby, I just issue the following command:
This will go automatically go out, fetch the desired version of Ruby, compile and install it in your home directory. It’s important to note that rvm does not install anything in any system directories, it keeps everything locally in your home directory. After compiling and installing, I should be able to do this:
This shows all installed versions of ruby on my system. In this case, I have 1.8.6 and 1.8.7 installed in my home directory, and 1.9.1 installed at the system level. The hash rocket pointing to 1.9.1 indicates that that is the current version that will be globally used. If I want to switch to using 1.8.6, I do this:
Notice how it now points to the version of ruby we just installed. If you do a ruby –version you’ll see that it works quite well:
Just like magic!
working with gems
You’ll have to install all the gems you need for each version you plan to run. You can do this like you would in a system ruby install, but DON’T USE SUDO. Remember that the versions of ruby you installed are stored in your home directory, so you want to make sure they are written with normal user priveleges. I noted that there is a feature ‘gemdup’ which is supposed to let you copy over gems from one install to another, but I couldn’t get it to work correctly (it is marked as experimental, so I’ll give that some time to mature). I could not get ‘gemdir’ to succesfully switch the gem directory either, but this isn’t that big of a deal.
Overall I’m really pleased with rvm. Now I can cut ruby gems like a pro. :-)