Managing rubies with chruby

I've been using rbenv and ruby-build to manage my rubies for the past two years, but I recently made the jump to chruby and ruby-install. So, why the switch?

You don't need to care about patchlevels unless you want to

rbenv installs gems per ruby binary, so each patchlevel has its own set of gems. Also, it has no support for fuzzy matching in .ruby-version files. In practice, this means that whenever a project's .ruby-version gets bumped up everyone working on it has to upgrade. This means updating ruby-build, building the new ruby and then re-installing all gems for the new version (or using rbenv-default-gems). This makes life way harder than it needs to be, and might come across as bit insane to team members with little ruby experience.

In our experience, which patchlevel you're running in development rarely matters. This is especially true when you're deploying to Heroku and can't specify a patchlevel for production anyway.

With chruby you can specify 2.0.0-p353, 2.0.0, or even just 2.0 or 1.9 in your .ruby-version and it will use the most recent ruby you have installed that fits the bill. Also, chruby shares the same set of gems across all patchlevels of the same version, so you only need to re-install gems when you move to a new version, e.g. from 1.9.3 to 2.0.0.

ruby-install is easier to use

Unlike with ruby-build you don't need to update ruby-install every time there is a new patchlevel release. Also, you don't need to concern yourself with what patchlevel to get, running ruby-install ruby will simply get you the latest stable release.

Getting up and running

  1. Install chruby and ruby-build. I recommend using Homebrew.
  brew install chruby ruby-install

Also, install ruby dependencies:

  brew install gdbm libffi libyaml openssl readline

Add these lines to your ~/.bash_profile (or equivalent):

  source /usr/local/share/chruby/
  source /usr/local/share/chruby/

Install the latest ruby (MRI):

  ruby-install ruby

Now, the script we load in .bash_profile automatically enables whatever ruby is defined in .ruby-version in the current or a parent directory. So to use the chruby ruby by default just create a ~/.ruby-version containing 2.0.0 (or whatever you prefer).

Loading comments…
All rights reserved