Now that Ruby 1.9.1 is out, a lot of Ruby developers are going to want to run it alongside a 1.8.x build to test their apps. Here’s how to compile and install Ruby 1.9.1 alongside an existing Ruby installation on Mac OS X Leopard without disturbing that installation or any gems.
Note: You’ll need to have Xcode installed, since it provides the development tools necessary for the compilation step. If you don’t already have Xcode, you can install it from your Mac OS X installation DVD or download it from Apple for free.
First, download and extract the release:
curl ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.9.1-p0.tar.bz2 -o ruby-1.9.1-p0.tar.bz2
tar xjf ruby-1.9.1-p0.tar.bz2
Next, compile Ruby, specifying a suffix for the binaries. This will create binaries named ruby19
, irb19
, gem19
, etc., which will coexist peacefully with the stable ruby
, irb
, and gem
binaries:
cd ruby-1.9.1-p0/
autoconf
./configure --program-suffix=19 --enable-shared --with-readline-dir=/usr/local
make && sudo make install
That’s all there is to it.
Update: Updated to resolve potential readline-related errors.
Update 2: The stable release of 1.9.1 is now out, so I’ve updated the instructions accordingly.