1.4. Mac OS X 10.7 - Installation of Ruby on Rails 3.2 with RVM

The number of Ruby on Rails developers who use Mac OS X is encouragingly high. On Rails conferences, you usually see around 80 % of participants with a MacBook.
Mac OS 10.7 includes Ruby version 1.8.7 as standard. Not interesting for our purposes. We want Ruby 1.9.3 and Rails 3.2. To avoid interfering with the existing Ruby and Rails installation and therefore the packet management of Mac OS X, we install Ruby 1.9.3 and Rails 3.2 with RVM (Ruby Version Manager).
With RVM, you can install and run any number of Ruby and Rails versions as normal user (without root rights and in your home directory). So you can work in parallel on old projects that may still use Ruby 1.8.7 and new projects that use Ruby 1.9.3.


Detailled information on RVM can be found at the RVM homepage at https://rvm.io/.


If you are reading the printed book version of this chapter, please check the online version at http://xyzpub.com/en/ruby-on-rails/3.2/. Each update of the operating system or RVM also usually involves an update of the installation instructions.

Xcode Installation or Upgrade

Before you start installing Ruby on Rails, you must install the latest Apple Xcode tools on your system. The easiest way is via the Mac App Store (search for "xcode") or via the website https://developer.apple.com/xcode/.

Installing Ruby 1.9.3 with RVM

Open a terminal with your normal user rights and check which Ruby version is installed:
$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
RVM can be installed in various ways. I recommend using the following monster command (please copy it exactly) that installs the latest RVM:
$ curl -L https://get.rvm.io | bash -s stable
RVM is now installed. You can now either close your terminal window (and therefore your active shell) or load the required parameters as follows:
$ source ~/.rvm/scripts/rvm
To test if rvm is correctly installed, let's try calling it with -v:
$ rvm -v

rvm 1.16.20 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

If you should get the bash command not found as reply, you need to check the above steps again. You probably accidentally skipped a step (for example, forgot to reopen the terminal).
The following command displays the rubies (Ruby interpreters) that RVM knows.[3]:
$ rvm list known
# MRI Rubies


There are different interpreters for Ruby. The relevant one for us is the normal MRI (Matz's Ruby Interpreter) [4], whose core is the Ruby VM with the name YARV (Yet Another Ruby VM) [5] as of Ruby 1.9.


A printed book cannot keep up with the dynamics of Apple, Ruby and RVM. Please read the output of RVM carefully and have a look at the companion website of this book (http://xyzpub.com/en/ruby-on-rails/3.2/).
Now you can use RVM to install Ruby 1.9.3 in the new terminal:
$ rvm install 1.9.3
RVM changes the default Ruby directly to the version you just installed:
$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.1]


With the command rvm system you can switch back to the system Ruby version 1.8.x any time.


You can enter the command rvm to display a corresponding help page with further available commands.

Generate Ruby Documentation

Ruby has an integrated and constantly accessible documentation (see the section called “Help via ri”). If you want to install this (and I highly recommend you do), you now need to run rvm docs generate:
$ rvm docs generate

Installing Rails

First, we check if your shell runs Ruby in version 1.9.3. If this is not the case, please read the section called “Installing Ruby 1.9.3 with RVM”.
$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.1]
Then we make sure that the gem package management is up to date:
$ gem update

Installing Rails 3.2

The rest is easy:
$ gem install rails --version '~> 3.2.0'
Perfect. You have now installed Rails 3.2.
$ rails -v
Rails 3.2.9


If you want to install an older Rails version one day, you can edit the parameter --version and insert the corresponding older version number (for example --version '~> 3.1.0' for the most current Rails 3.1 version).

And Now?

If you have never worked with Ruby before, you should first read Chapter 2, Ruby Basics. If you are already a Ruby master and want to move on to Rails now, then I recommend reading Chapter 3, First Steps with Rails.

Updates about this book will be published on my Twitter feed.