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
February 2nd, 2008 at 04:42 PM
Thanks Mikel!
This was the info I needed (for 10.4 Tiger). Cool
Cheers! sinclair
March 8th, 2008 at 09:10 AM
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
April 19th, 2008 at 07:35 AM
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
February 1st, 2009 at 08:17 PM
you guys also might want to take a look at the ruby one-click installer for osx: http://rubyosx.com
we are currently preparing binaries for leopard, tiger and panther for the stable ruby 1.9.1-p0
February 28th, 2009 at 09:41 AM
If you have MacPorts, just type:
sudo port install ruby19
And go get a drink like the lazy ass you are. When you return, it’ll have downloaded, compiled, and installed Readline for you, and then done the same for Ruby. (Updates to either are just as easy.)
The only gotcha is it installs into the MacPorts directory /opt/local/bin, while the standard Ruby location is /usr/bin. If you want to put it there and make it the standard Ruby version for your mac, add the following:
cd /usr/bin sudo ln -s /opt/local/bin/ruby1.9 . sudo mv ruby ruby1.8 sudo ln -s ruby1.9 ruby
Done!
February 28th, 2009 at 09:51 AM
Ack, it mangled my last lines! Here’s the four commands to then make 1.9 standard on your mac:
cd /usr/bin
sudo ln -s /opt/local/bin/ruby1.9 .
sudo mv ruby ruby1.8
sudo ln -s ruby1.9 ruby
February 28th, 2009 at 09:55 AM
You might want to put the new irb in /usr/bin too…
cd /usr/bin
sudo ln -s /opt/local/bin/irb1.9 .
sudo mv irb irb1.8
sudo ln -s ruby1.9 irb
March 20th, 2009 at 06:45 PM
Thanks for the tips Rich, they were very helpful. The last line in your above post should read
sudo ln -s irb1.9 irb
otherwise…
March 20th, 2009 at 06:53 PM
Thanks for the tips Rich, they were very helpful. The last line in your above post should read
sudo ln -s irb1.9 irb
otherwise…
June 12th, 2009 at 04:36 PM
Hmmm I followed these instructions exactly and now I get “ruby: command not found”
ls -la /usr/bin/ruby* ruby -> ruby1.9 ruby1.8 -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby ruby1.9 -> /opt/local/bin/ruby1.9
what is up with that?
June 12th, 2009 at 04:54 PM
Figured it out, the original article is missing sudo make install
I ran that and now all is well.