I had to walk a friend through an install of Ruby on Rails on a Macbook Air running Mac OS X Lion today and it was much more complicated than I remember it being.

This article outlines the steps to install Ruby 1.9.3 and Rails 3.2 using RVM (Ruby Version Manager)

RVM (https://rvm.io/) allows you to have more than one version of Ruby installed that you can easily switch between without interfering with the standard OSX installed version of Ruby.

RVM is not strictly necessary because the current version of Rails (3.2) does support the version of Ruby that is included with OSX Lion (1.8). However 3.2 is the last version of Rails that will support 1.8 and Ruby 1.9.3 is the recommended version. Installing RVM and using it to manage your Ruby installs lets you head off any version conflict problems you might have in the future. It also provides a great testing environment.

MacPorts is required to install a cryptography library (libksba) that is required by Ruby 1.9.3.

Xcode is required for MacPorts and RVM. However RVM requires you to install the Xcode command-line developer tools. You need an Apple developer account to download those. You only need to create a free account though, you don’t need to join the iOS or Mac Developer Programs.

For each step requiring Terminal commands, I recommend opening a new instance of Terminal, performing those commands and then quitting Terminal. This ensures that each time you open Terminal the changes made in the previous steps will be in effect.


Installing Ruby on Rails on Mac OSX Lion

  1. Install XCode and XCode command line tools

    You can download this from the Mac AppStore. It’s about 1.5 Gig. Once Xcode has downloaded and installed: launch it, click Cancel on the Welcome screen, go to the XCode menu, Open Developer Tools, More Developer Tools. This takes you to the web page on https://developer.apple.com that has the download for Command Line Tools for Xcode. You will need to sign in to your account on the site and if you don’t have an account already you can create one. Once you have signed in, download the most recent version of the Command Line Tools for Xcode .dmg file. Once it has downloaded, open it and run the installer package.

  2. Install the Ruby Virtual Machine Manager (RVM)

    The installer for RVM is a shell script that can be downloaded and run with the following terminal command:

    curl -L https://get.rvm.io | bash -s stable
    
  3. Install MacPorts

    Install MacPorts by heading to the MacPorts website and downloading the installer for OSX Lion, http://www.macports.org/install.php. Open the .dmg file and run the installer package.

  4. Install libksba

    Install the libksba library using Macports with the collowing terminal command:

    port install libksba
    
  5. Install Ruby with RVM

    Install Ruby 1.9.3 as your default Ruby using RVM with the following two terminal commands:

    rvm install 1.9.3 --with-gcc=clang
    rvm use 1.9.3 --default
    
  6. Install Rails

    Now that Ruby 1.9.3 is successfully installed, install Rails using the following terminal command:

    gem install rails
    

    You will now have Ruby 1.9.3 and Rails 3.2 installed and ready to use. Rails might report a couple of errors when setting up its documentation, this is not something to worry about.


To test your new installation, create a simple application:

There is no better way to test an install than spinning up a simple app. Open Terminal and perform the following steps:

  1. Create a new Application called WidgetManager

     rails new WidgetManager
    
  2. Create the model and generated CRUD pages for the model

     cd WidgetManager
     rails generate scaffold Widget code:integer name:string description:text
    
  3. Setup the database

     rake db:migrate
    
  4. Lanch the application using the included WEBRick webserver.

     ./script/rails server
    
  5. View the application

    Open the URL http://0.0.0.0:3000/widgets in your webbrowser.

    The WidgetManager application with a widget added.


And that’s it. You have Ruby 1.9.3 and Rails 3.2 installed with RVM. Enjoy.