rooting with rvm

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:// 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:

28 thoughts on “rooting with rvm”

  1. I installed per the instructions above, but rvm is only fully functional under my root account.

    I have a project with an .rvmrc file:

    rvm ree-1.8.7

    When I cd into the project folder as a root, I get the message from rvm saying I need to install ree-1.8.7.

    If I exit root, and return to my regular user, I don't get that error message from rvm.

    Using Ubuntu Lucid, here is my terminal output:

    chris@carson:~$ sudo -i
    root@carson:~# cd /httpd/draftblast

    warn: ree ree-1.8.7-2010.02 is not installed.

    info: To install do: 'rvm install ree-1.8.7-2010.02'
    root@carson:/httpd/draftblast# exit
    chris@carson:~$ cd /httpd/draftblast

    Note the error message when using root account, no error message under regular account.

    When I reviewed the env variables for both accounts, it looks like the root env shows all of the rvm path variables, but the regular account does not. Any suggestions?

    I think just copying the missing env variables from root to my regular user would work, but before I do that I want to make sure that I haven't configured anything incorrectly or if anyone else has had this problem running the instructions given here?

    Thank you!!

  2. I made a few tweaks to your script and put them up in a new gist. There were a few bad newlines (/n instead of n) and I moved the RVM sourcing script into a profile.d script. This works with CentOS 5.3-5.5. I haven't looked to see if the others use profile.d.

  3. You will need to also add

    # 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"

    to the end of "/etc/bashrc" file in order for capistrano to properly detect the path to rake. Otherwise your cap deployment script will fail for any task that needs to run rake.
    My recent post knowing where you’re going greatly increase your chances of getting there

  4. Just some comments about the functioning of the script itself.

    The packages you install on Debian/Ubuntu systems … I think you want 'git-core' not 'git', 'libreadline-dev' instead of 'libreadline5-dev' (on recent Ubuntu's at least, but it's probably true on others) and you don't want 'readline-devel' as that doesn't exist.

    Also, after you do the install of "rvm-$version", you run "rm -rf rvm", however I think you really want "rm -rf rvm-$version".

    One problem we ran into is that packages installed into /usr/local/rvm are owned by the user and if you have more than one user using this setup, permissions start to get in the way. We're solving it by changing the chmod -R g+w of /usr/local/rvm to this:

    chmod -R g+ws /usr/local/rvm

    and by changing the umask of the users who login and who'll be using this to 002. Ultimately, it would be nice if rvm had a "group ownership" flag which would tell it to do a g+w on files it creates, a-la git's "sharedRepository" setting.

    Thanks for the article, definitely useful!

  5. Thanks for the pointer – I changed it. I also posted the script as a gist, so feel free to fork, and improve.


  6. Quick improvement… in your experimental rvm group management, you should use 'chmod -R g+w /usr/local/rvm' instead of an explicit 744. This will preserve all other permissions and just add group-write capabilities.

  7. Glad to hear that it worked for you! Really odd about the system ruby requirement however – I have never run into that.

  8. Excellent article. I followed the instructions on a fresh install of Debian 5.04 Lenny. When I tried

    rvm install 1.9.2-head

    it failed. In my case, a system ruby had to exist, so

    apt-get install ruby

    before using rvm.

  9. When you source rvm in your /etc/bashrc did you read the stuff about return statements? That's a gotcha. rvm should set that all up for you, and when you start a new session it 'jest works'. :-)

  10. Thanks a lot, just an update.

    The problem is that with rvm I don't have the gem EXECUTABLE DIRECTORY included in my PATH

  11. I really don't use sudo – I just make sure that who ever is going to need to admin the machine's rvm install is a member of the group that owns the directory. And, if you sudo, you'll want to make sure that you do something like
    sudo su
    rvm use blah
    gem install blah

  12. hi, just curious if you are having problems with rails.
    if I do
    sudo gem install rails
    everything goes fine but afterwords even if gem list shows rails
    rails –version
    gives me a no command error.

    Any hints?

  13. That is a good point. I've seen sudo have wildly different incantations to get it running.

    debian: sudo su works
    centos sudo su - works
    mac sudo su works

    rvm is really nice – It's sure made my life easier.

  14. Just a nitpick but you want to use sudo -i instead of sudo su. That will give you a full root shell. sudo -s will give you a root login but it won't run the root's .bashrc which is similar to sudo su.

    Nice article though, I think you've finally convinced me to use rvm.

Leave a Reply