Skip to content

Update Ruby and Rails on Mac OS X

November 24, 2011

The system version of Ruby is a bit outdated. In order to update it you should install the Ruby Version Manager or RVM, and not touch the System’s Ruby version. Trying to install it through MacPorts also gave me a bunch of problems, especially in OS X Lion (10.7).

This install also requires Git Version Control system.
If you’re using MacPorts you can install it by running

sudo port install git

But like I said some Ruby and Rails applications do not play well with MacPorts so you will sooner or later should migrate to Homebrew. Here is one of such problems due to mismatched OpenSSL MacPort library versions, that caused me to have to reinstall the whole thing…

Well using the system’s version of ruby it is easy to install Homebrew:

ruby -e "$(curl -fsSL"

and then install Git

brew install git

Now you can install RVM. Just Copy & Paste the whole line and run it as a single line in your terminal

bash < <(curl -s )

I usually install RVM in my home directory, and run the previous command with my regular user. This is ok since we mostly use our Macs for development, with only one developer on that machine.

If you need to install RVM system wide you can run:

sudo bash < <(curl -s )

Now you need to add RVM to your shell so it can do its magic.

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bash_profile

Close your Terminal and reopen it. This will force it to process the code we just entered into .bash_profile. You can also run the following:

. ~/.bash_profile

Now you need to make sure you have the latest Xcode from Apple. You can download it from the App Store for free, or install it from your Mac OS X installation DVD.

If you are a die hard fan of MacPorts, please remove it from the PATH so Ruby does not compile against its libraries causing all sorts of errors later on. It usually suffices to remove all references to /opt/local from the /etc/profile, but your configuration maybe a little bit different.

Now that you have installed Xcode and removed the MacPorts from the PATH you can continue 🙂

At the time of this writing the current stable version of Ruby was 1.9.3 so that is what I use, you should probably use the latest sable version, and not 1.9.3, by the time you follow this procedure…

rvm install 1.9.3

If you’re on Mac OS X Lion 10.7.2 with Xcode 4.2.1 you may get a compilation error. In that case run

rvm install 1.9.3 --with-gcc=clang

Once it finishes downloading, compiling and installing ruby you can do

rvm --default use 1.9.3

To use the ruby version we just installed, and to make it the default version.

RVM is kind of neat since it does not disturb the system version of Ruby and allows you to maintain and work with different versions of Ruby so you can make sure your older projects that require older versions of Ruby, Rails or some other Gem still run even when you upgrade to newer versions.

RVM is kind of like a virtual machine, or environment that allows you to keep separate Ruby installs that will coexist peacefully, and that is why you should use it and not replace the system Ruby version.

RVM allows for the creation and use of several Gem Repositories or gemsets, that you can keep for each of your projects, and this is an invaluable feature so you don’t get stuck into gem dependency issues later on.

By default a global gemset is created and all gems installed to global will be shared among all the other gemsets that you create for a specific ruby version maintained by RVM.
You should install gems, that like Rails, will be shared by all projects running under a Ruby version. So lets install some of the basic gems to get us going.

rvm gemset list

You should get something like:

gemsets for ruby-1.9.3-p0 (found in /Users/pedro/.rvm/gems/ruby-1.9.3-p0)

Lets double check that we’re using the Ruby version we just installed:

bigdiver$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
bigdiver$ gem -v

Install sQlite3, JSON, and Rails

gem install sqlite3 json rdoc rails cheat

If you get UTF-8 errors just set the LANG and LC_CTYPE environment variables. I usually do it in the /etc/profile, but you can do it in the .bash_profile in your home directory.
Add the following lines to one of them and “source” them into your environment

export LC_CTYPE="utf-8"
export LANG=en_US.UTF-8

. /etc/profile


. ~/.bash_profile

And then install your gems.


From → Apple, Ruby on Rails

  1. why not just “brew install ruby”?

Trackbacks & Pingbacks

  1. Working with Ruby Version Manager « BigDiver

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: