Installing Ruby 1.8 and 1.9 on Ubuntu from Source

Posted by Ryan Baxter Sun, 14 Sep 2008 20:30:00 GMT

I’ve begun testing my fractal library with the latest source code from the Ruby 1.9 trunk. Since 1.9 is a development release and I still need 1.8 for my Rails applications, I’ve checked out both versions and configured them to run side-by-side on Ubuntu, Hardy Heron.

Before you begin, make sure you have the autoconf, build-essential, and subversion packages installed.

It may also be a good idea to include the Ruby1.8 and Ruby1.9 build dependencies from Ubuntu’s package repository. This could prevent some headaches later on.

$ sudo apt-get build-dep ruby1.8 ruby1.9

Create a directory for the Ruby source code.

$ mkdir /home/ryan/source
$ cd /home/ryan/source

Check out the code from the 1.8 branch. Since this branch includes patches, you can always update your source and recompile when new patches are released.

$ svn co http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8 ruby1.8

Next, create a configuration, configure, and compile.

$ cd ruby1.8
$ autoconf
$ ./configure --prefix=/opt/ruby1.8 --program-suffix=1.8
$ sudo make
$ sudo make install

Finally, link your new binaries to the /usr/local/bin directory.

$ sudo ln -s /opt/ruby1.8/bin/* /usr/local/bin

Typing ruby1.8 -v in a new console should yield something similar to the following:

$ ruby1.8 -v
ruby 1.8.7 (2008-09-15 revision 19348) [i686-linux]

One of the best parts of Ruby is Rubygems! Download and install it.

$ wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
$ tar -xvzf rubygems-1.2.0.tgz
$ cd rubygems-1.2.0
$ sudo ruby1.8 setup.rb
$ sudo ln -s /opt/ruby1.8/bin/gem1.8 /usr/local/bin

The current source for Ruby 1.9 requires version 1.8 to compile, but if you’ve followed my directions up to this point you should be ready to download and compile the latest Ruby 1.9 source code.

Go back to your source directory and check out the latest code from the 1.9 trunk.

$ cd /home/ryan/source
$ svn co http://svn.ruby-lang.org/repos/ruby/trunk ruby1.9
$ cd ruby1.9

This time use the –with-baseruby switch when configuring. Set this option to the new Ruby 1.8 binary and then compile.

$ autoconf
$ ./configure --with-baseruby=/usr/local/bin/ruby1.8 --prefix=/opt/ruby1.9 --program-suffix=1.9
$ sudo make
$ sudo make install

Finish by linking your new Ruby 1.9 binaries to /usr/local/bin.

$ sudo ln -s /opt/ruby1.9/bin/* /usr/local/bin

Typing ruby1.9 -v in your console should yield something similar to the following:

$ ruby1.9 -v
ruby 1.9.0 (2008-09-15 revision 19351) [i686-linux]

Ruby 1.9 includes Rubygems! We’re done!

Since the binaries we’ve created have been suffixed with either 1.8 or 1.9, you must remember to execute them with their proper name ie (gem1.8, gem1.9, ruby1.8, ri1.9).

I’ve written these instructions from memory so if you have any problems, please post them and I’ll try to help out as best I can. Please be warned, however, that not all code written for Ruby 1.8 will work in 1.9.

Comments

Leave a response

Avatar
Matt Scilipoti Comment_bubble 7 months later:
Thank you. This was very helpful.
Avatar
Mike Turner Comment_bubble 7 months later:
Thanks for taking the time to share that. It's just what I was looking for.
Avatar
Ryan Baxter Comment_bubble 7 months later:
I'm glad this was helpful. I've been meaning to update it since the release of Ruby 1.9.1. Maybe I'll make time when Ubuntu 9.04 comes out later this month.
Avatar
Long Tran Comment_bubble 9 months later:
Thanks for your article, it's very helpful. :)
Avatar
Ryan Baxter Comment_bubble 12 months later:
Why didn't someone tell me that the steps were out of order! :P I just tried to follow my own directions on a fresh install and had a problem installing rubygems without first having a symlink. Its been fixed.