Ruby on OS X 10.7.3

I’ve been working my way through the excellent Learn Python The Hard Way programming book and to further expand my knowledge of programming wanted to also work through Learn Ruby The Hard Way, but was having a tough time getting my Macbook Pro set up with a newer version of Ruby. Hopefully this post saves someone else some time struggling with Xcode, gcc, make, etc.

By default OS X 10.7.3 comes with Ruby 1.8.7 and doesn’t have gcc, make, etc. in order to be able to download, compile and install the newer version (1.9.2+) of Ruby recommended by Learn Ruby The Hard Way. Rather than going through all the trial and error, installs, uninstalls, reinstalls, mistakes and reboots I made in getting this to work, here’s the steps that finally worked for me without having to install the bloatfest that is Xcode:

1. Download and install the relevant OSX-GCC-Installer for your version of OS X
2. Download and install RVM: Ruby Version Manager with the following command in a terminal window:

$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

After a while you should see:

Downloading RVM from wayneeseguin branch stable
 % Total % Received % Xferd Average Speed Time Time Time Current
 Dload Upload Total Spent Left Speed
100 919k 100 919k 0 0 188k 0 0:00:04 0:00:04 --:--:-- 308k

Upgrading the RVM installation in /Users/sphericaln/.rvm/

RVM PATH line found in /Users/sphericaln/.bashrc /Users/sphericaln/.zshrc.

RVM sourcing line found in /Users/sphericaln/.bash_login /Users/sphericaln/.zlogin.

Upgrade Notes:
* ZSH 4.3.15 is buggy, be careful with it, it can break RVM, especially multiuser installations,
You should consider downgrading ZSH to 4.3.12 which has proven to work more reliable with RVM.

# RVM: Shell scripts enabling management of multiple ruby environments.
# RTFM: https://rvm.beginrescueend.com/
# HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
# Screencast: http://screencasts.org/episodes/how-to-use-rvm
# In case of any issues read output of 'rvm requirements' and/or 'rvm notes'

Upgrade of RVM in /Users/sphericaln/.rvm/ is complete.

# Andrew Frayling ,
#
# Thank you for using RVM!
# I sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne

3. Quit and relaunch terminal to pick up the environment variables that the RVM installer sets.
4. Update RVM by running the following command in a terminal window:

$ rvm get latest

After which you should see:

rvm-1.10.2
 % Total % Received % Xferd Average Speed Time Time Time Current
 Dload Upload Total Spent Left Speed
100 802k 100 802k 0 0 181k 0 0:00:04 0:00:04 --:--:-- 189k

Upgrading the RVM installation in /Users/sphericaln/.rvm/

RVM sourcing line found in: /Users/sphericaln/.bash_login.

Upgrade Notes:
# RVM: Shell scripts enabling management of multiple ruby environments.
# RTFM: https://rvm.beginrescueend.com/
# HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)
# Screencast: http://screencasts.org/episodes/how-to-use-rvm
# In case of any issues read output of 'rvm requirements' and/or 'rvm notes'

Upgrade of RVM in /Users/sphericaln/.rvm/ is complete.

# Andrew Frayling ,
#
# Thank you for using RVM!
# I sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne

Installed RVM version:
rvm 1.10.2 by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.beginrescueend.com/]

RVM reloaded!

5. Update Ruby to 1.9.3 with the following command in a terminal window:

$ rvm install 1.9.3

Compiling takes a while, but you should eventually see:

Fetching yaml-0.1.4.tar.gz to /Users/sphericaln/.rvm/archives
Extracting yaml-0.1.4.tar.gz to /Users/sphericaln/.rvm/src
Configuring yaml in /Users/sphericaln/.rvm/src/yaml-0.1.4.
Compiling yaml in /Users/sphericaln/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/sphericaln/.rvm/usr
Installing Ruby from source to: /Users/sphericaln/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)...

ruby-1.9.3-p0 - #fetching
ruby-1.9.3-p0 - #extracting ruby-1.9.3-p0 to /Users/sphericaln/.rvm/src/ruby-1.9.3-p0
ruby-1.9.3-p0 - #extracted to /Users/sphericaln/.rvm/src/ruby-1.9.3-p0
ruby-1.9.3-p0 - #configuring
ruby-1.9.3-p0 - #compiling
ruby-1.9.3-p0 - #installing
Removing old Rubygems files...
Installing rubygems-1.8.15 for ruby-1.9.3-p0 ...
Installation of rubygems completed successfully.
ruby-1.9.3-p0 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.3-p0 - #importing default gemsets (/Users/sphericaln/.rvm/gemsets/)
Install of ruby-1.9.3-p0 - #complete

6. Set Ruby 1.9.3 as the default with the following command:

$ rvm use 1.9.3 --default

and you should see:

Using /Users/sphericaln/.rvm/gems/ruby-1.9.3-p0

7. Check that 1.9.3 is now the default with:

$ ruby -v

and you should see:

 ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.3.0]

Seemples!!!

Hope this saves someone else some time. Happy coding :-)