rvm (ruby version manager) is a kick ass tool that I use on a daily basis. It allows you to install lots of ruby versions, gems, gem sets, and what have you. You can test your app against new (or old) versions of ruby easily. You can also use it to manage rubies on a production system, for all users of that system.

Yes, you heard me correctly. After needling Wayne into getting root support built into RVM so many weeks ago, this is really the only way that I use it. There are a few gotchas however. I will go through my best practices for installing rvm system wide in this article.

updated: 8/1/2010 : @sutto and @wayneeseguin have baked root support into rvm - use that!


The first step is to prep the system for rvm.

On a ArchLinux system run the following:

pacman -S --noconfirm gcc gcc-libs make kernel-headers zlib libtool bison gdb strace gettext openssl git readline


yum install -y gcc gcc-c++ kernel-devel zlib libtool bison gdb strace gettext git rpm-build redhat-rpm-config zlib-devel openssl openssl-devel git readline-devel


aptitude install -y build-essential libreadline5-dev libssl-dev bison libz-dev zlib1g zlib1g-dev libxml2 libxml2-dev libxslt-dev libssl-dev openssl git readline-devel

And on your Mac, you’ll want to get the latest XCode installed.

Install rvm

I normally add gem: --no-rdoc --no-ri to the /etc/gemrc file. I really dislike getting all of the RI and RDoc stuff generated, at it normally takes more time then the gem install.

When I install the base rvm package, I tend to use the latest git head. That way, I do not need to muck about getting ruby and rubygems installed on the machine in question. As long as I have git, I am good to go.

cd ~
git clone git://github.com/wayneeseguin/rvm.git temp_rvm
cd temp_rvm

This is all straight forward up to this point. We’ve done everything “by the book” as it were. From here on out, be advised that installing things as root might cause breakage or instability.

Here there be dragons

We’ll start off with this:

sudo su

and then continue from the temp_rvm directory we just created:

cd ~
rm -rf temp_rvm

Now, you should have a non-working rvm install located in /usr/local/rvm. We are almost done, just a few more little things left.

First off, create a /etc/rvmrc file and add this line:

export rvm_path=/usr/local/rvm

Next, edit your /etc/profile to include the following line on the bottom:

# Load RVM if it is installed,
#  first try to load  user install
#  then try to load root install, if user install is not there.
if [ -s "$HOME/.rvm/scripts/rvm" ] ; then
  . "$HOME/.rvm/scripts/rvm"
elif [ -s "/usr/local/rvm/scripts/rvm" ] ; then
  . "/usr/local/rvm/scripts/rvm"

Cleaning up

You’ll want to chown the /usr/local/rvm directory to add a group that contains the folks you want to be able to administrate your rubies, install gems and what not. I then chmod -R g+w /usr/local/rvm to allow the group access. I have had mixed luck with this - best case scenario is to grant ownership to the 1 user who is going to be tasked with loading rubies and tell him to get at it.

I also use the rvm use ruby_version --default option when I select a ruby for use system wide. It works really well.

Closing thoughts, and a present for all that read this far...

rvm is an excellent tool. I have run it on several production systems as root, and only run it that way any more. It sits next to homebrew on my Mac, and makes testing stuff super simple.

Here is the setup script that I use which automates everything above: