Building Ruby 1.9 on Mac OS X 10.5 (Leopard)

I’ve recently been learning Ruby, and I wanted to install Ruby 1.9 on OS X to try out some of the new features (the current ‘stable’ version of Ruby is 1.8.6). Unfortunately, I couldn’t find one cohesive guide to doing this, and instead had to mash together various instructions from across the interwebs. I’ve pieced everything together here in the hope that it’ll help out someone else. 🙂

Step 1

Firstly, readline needs updating, so grab readline 5.2 from http://ftp.gnu.org/gnu/readline/. After extracting it (tar xvzf readline-5.2.tar.gz) you’ll need to make one or two changes so that it will build correctly on Leopard. Simply apply this readline patch to support/shobj-conf in the readline directory you’ve created. The patch is necessary because readline currently doesn’t check for Leopard, only for earlier versions of OS X. In fact, the patch is simple enough that you could change the two lines by hand if necessary.

Then, configure readline, specifying a location so you don’t interfere with what’s already on your system, then build and install it:

./configure --prefix=/usr/local/
make
sudo make install

Step 2

Next, you’ll want to download Ruby 1.9: http://ftp.ruby-lang.org/pub/ruby/1.9/. Again, we want to specify our own install location, and we also need to tell it where our newly installed readline is. We’re also specifying a program-suffix here (-trunk) so we can differentiate Ruby 1.9 from our pre-installed Ruby (so we’ll access 1.9 with ruby-trunk, irb-trunk, etc, and 1.8.6 with ruby, irb, etc).

tar xvzf ruby-1.9.0-1.tar.gz
cd ruby-1.9.0-1
./configure --prefix=/usr/local/ruby1.9 --program-suffix=-trunk --with-readline-dir=/usr/local --
make
sudo make install

Step 3:

Finally, because we’ve installed Ruby in a specific location, you’ll most likely need to add its location to your path. I have a bin/ directory in my home directory, so I simply have the following line in my .bash_profile:

# Add Ruby 1.9
PATH=$PATH:/usr/local/ruby1.9/bin

And you’re done. You can test by running ruby-trunk --version. Any problems, sound off in the comments. I may have missed something, as it’s rather late – and I could’ve almost certainly written this better. Hopefully I’ll revisit it in the future. If you get stuck, the articles I used to put this together might be of use: