Installing Ruby 1.9 on Mac OSX

January 18th, 2008

If you have ruby and a mac, no doubt you want to try out 1.9 – but be warned, some things can break! This little tutorial shows you how to install Ruby 1.9 in parallel to your 1.8.x installation… which can be handy…

Especially useful if you are developing an application in Ruby and want to test against 1.8.x and 1.9.

The goal here is to end up with a set of tools that can be 1.8 or 1.9 at will. The way I will do it is that you will end up with “ruby” and “irb” and “rake” and “gem” all pointing to your existing version of Ruby (be that 1.8.6 or 1.8.5 or whatever). Then you will get another set of tools like “ruby-trunk”, “irb-trunk”, “rake-trunk” and “gem-trunk” that will point to the 1.9 versions of these programs.

So, sound good? Great, enough talk, lets get started.

Getting Ruby

You can download Ruby 1.9 from http://www.ruby-lang.org/en/downloads/

Getting Read Line

You will most likely need Read Line 5.2 (Ruby 1.9 needs it), so you can get it from the readline GNU page

Installing ReadLine

Do the following from your home directory:

baci:~ mikel$ tar xvzf readline-5.2.tar.gz 
baci:~ mikel$ cd readline-5.2
baci:~/readline-5.2 mikel$ ./configure --prefix=/usr/local/
baci:~/readline-5.2 mikel$ make
baci:~/readline-5.2 mikel$ sudo make install

This will make and install Read Line for you.

But if you are on Leopard, this might not work as planned, so replace the “make” above with:

baci:~/readline-5.2 mikel$ make static
baci:~/readline-5.2 mikel$ sudo make install-static

Thanks to Sean’s webblog for this tip.

Installing Ruby 1.9

Now you need to get Ruby working, you do this by doing the following:

baci:~ mikel$ tar xvzf ruby-1.9.0-0.tar.gz
baci:~ mikel$ cd ruby-1.9.0-0
baci:~/ruby-1.9.0-0 mikel$ ./configure --program-suffix=-trunk --with-readline-dir=/usr/local
baci:~/ruby-1.9.0-0 mikel$ make

Note the ./configure step? This is important because you are passing in two options, firstly you are telling it to add -trunk to the end of each program it makes (you could put anything you want here basically) and secondly you are telling it where to get ReadLine from on the system.

And that’s it!

To test, just try typing:

baci:~ mikel$ irb-trunk
irb(main):001:0> RUBY_VERSION
=> "1.9.0" 

Enjoy!

blogLater

Mikel

3 Responses to “Installing Ruby 1.9 on Mac OSX”

  1. sinclair Says:

    Thanks Mikel!

    This was the info I needed (for 10.4 Tiger). Cool

    Cheers! sinclair

  2. nick Says:

    I needed to follow these steps on 10.5 leopard to get ruby 1.8.6-p114 to install properly with support for irb. Thanks for the steps to get me through it.

    -Nick

  3. JB Says:

    in the readline ./configure, I think you should leave the trailing / off from /usr/local

    also, do you need to make install for Ruby too?

    and for Leopard, you might need a fix for readline? http://www.ruby-forum.com/topic/140471

Leave a Reply