User Tools

Site Tools

Table of Contents

Ruby

Mac OS X 10.8 comes with Ruby 1.8.7 (patch level 358). This version has been retired and the developers will no longer be supporting it.
Most Ruby programs now support Ruby 1.9.3 and/or Ruby 2.0.0.

There are several ways to support multiple versions of Ruby. The most popular are RVM and rbenv. We used to use RVM, but have switched to rbenv because it is focused and does its job with fewer tricks. Here's a list of reasons to prefer rbenv.

Installing rbenv

We install rbenv and ruby-build, which will integrate with rbenv to install the versions of Ruby we want.
We also install several rbenv plugins. The rbenv-gem-rehash plugin automatically runs rbenv rehash whenever necessary. The rbenv-vars plugin allows Ruby programs to define environment variables. The rbenv-binstubs plugin integrates with RubyGems and Bundler to make sure that the right version of Ruby is used to run any programs that require Ruby.

Updating

To update the versions of Ruby you have installed, first you have to upgrade ruby-build:

brew update
brew upgrade ruby-build
rbenv install--list

Then you can install the new version(s) of Ruby. Be sure to install all the basic gems, update your aliases and documentation.

Setting the Default Ruby

We'll set Ruby 2.1.1 as the default.

rbenv versions
rbenv global 2.1.1
rbenv shell 2.1.1

Installing Gems

We only need to install gems that we use outside of applications. This will generally be executables written in Ruby, or things we want inside of IRB. For everything else, we'll use Bundler to install applications-specific gems.

Binstubs

Binstubs are a bit tricky, but the general idea is to have a small executable in a directory in the front of the $PATH that will set up the environment, then call the real executable. For rbenv, the rbenv-binstubs plugin handles this for us, without having to add ./bin to the $PATH (which would be a security issue). It gets in front of the binstubs created by RubyGems and Bundler to ensure the proper version of Ruby is used.

To get this working, we need to tell Bundler to always create binstubs:

bundle config --global bin bin

NOTE: Rails 4 does not like Bundler's binstubs. You'll need to run rake rails:update:bin after running bundle install the first time, to override Bundler's binstubs with Rails' binstubs.