Just a Jot

A little blog on software development.

Farewell, RVM. Nice to Meet You, Rbenv.

RVM is a badass tool. My only significant gripe is that it slows down the creation of new Terminal windows, something I do quite often. While there are a few other concerning behaviors (such as the overriding of key system commands like cd), it’s the slowness of opening Terminal windows that really annoys me. I’m not dependent on much of the awesome functionality that RVM provides, so it’s time to try a new tool. Meet rbenv.

rbenv subscribes to the Unix philosophy of doing one thing and doing it well. It’s one job is managing multiple installations (and versions) of the Ruby programming language. It does nothing else.

Remove RVM

Since RVM stores everything in a single place, removing it from your system completely is a simple task. In fact, the rvm implode command provides most of this functionality for you.

$ rvm implode
$ sudo rm -rfd /etc/rvmrc
$ rm ~/.rvmrc

Within your .bash_profile (or whatever shell initialization file you typically use), there should be a line that initializes RVM:

[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm

Remove it. Farewell, RVM.

Install rbenv

rbenv is easier to install than RVM is to remove. Usually I like to refer to the awesome Homebrew package manager for OS X, and this time is no different.

$ brew update
$ brew install rbenv

Then add the following line to your .bash_profile:

eval "$(rbenv init -)"

rbenv is now installed. Now we need to install some Rubies! Remember when I mentioned that rbenv does one thing (and does it well)? Well, that one thing is MANAGING multiple Ruby versions, not installing them. To give rbenv the capability to install Rubies, you need another tool: ruby-build.

Install ruby-build

Installation of ruby-build is even simpler than rbenv:

$ brew install ruby-build

Install Rubies

Now you can install Rubies all day. Why not write a script to do it? See how fast you can fill up your hard drive with Ruby installations — wouldn’t that be a beautiful thing? Well, it’d probably just be a waste of hard drive space. But in any case …

To see a list of available versions, either of these commands will work:

$ rbenv install
$ ruby-build --definitions

Choose your favorite Ruby and install it:

$ rbenv install 1.9.2-p290
$ rbenv rehash

It’s necessary to run rbenv rehash after installing a new Ruby version or gems that include shell commands. This simply gives rbenv the knowledge it needs to run the correct commands.

If you want to install multiple copies of the same Ruby version, use ruby-build instead:

$ ruby-build 1.9.2-p290 ~/.rbenv/versions/1.9.2-p290-custom

Where “1.9.2-p290-custom” is the directory name where the new version will be installed.

Switch between

Globally:

$ rbenv global 1.9.2-p290
$ rbenv global 1.9.2-p290-custom

Per project:

Add the version name to the .rbenv-version within your project’s directory:

$ echo '1.9.2-p290-custom' > .rbenv-version

Or override the version within the shell completely:

$ export RBENV_VERSION='1.9.2-p290'

More information

For more and up-to-date information, please see the rbenv project page on GitHub.

Nice to meet you, rbenv. Boom goes the dynamite.