Installing ruby 1.9preview1 on OS X Leopard

Tonight I’m trying conciseness.

Editor’s note: I failed.

I recently decided to test my git_remote_branch gem with Ruby 1.9, for the heck of it. Well, I was making sure it ran on a bunch of platforms: Windows, Ruby 1.8.7 and with the most recent Git version (1.6.0.2, get it). So it seemed fitting to check it out under Ruby 1.9.

On Leopard, the only missing dependency to Ruby 1.9 is readline 5.2. This article will present the installation of both. And help heat up your apartment.

Linux too

These instructions will mostly work on Linux as well (tried on Ubuntu). There will be a few minor differences though.

Make sure you download the original readline from the gnu site and patch it yourself;

Uninstall older versions of Ruby1.9;

Make sure you have the basic dev tools installed, like gcc and make;

Skip the part about installing Xcode :-)

Prerequisites

You first need to have the Apple developer tools installed on your mac. They’re available on your installation CD. Put it in, run the installer. It’s pretty straightforward.

Once you’ve set yourself up, if you don’t care about the details, you can skip to the end for the Cliff’s notes.

Installing readline

This one’s not as straightforward as it could have been. The gzipped readline library available on the gnu site is 12 patches behind. It so happens that the 12th patch fixes a problem with compilation under OS X. So I applied all 12 to the code and repackaged it. The example uses that file, compiled by me.

You can also do do the patching by yourself if you so wish. Here’s where you can download the readline code:

Build Ruby 1.9

Build options

Note that here you have a few options as to how you want to distinguish your 1.9 stack from your main 1.8 one.

In the following example, I build Ruby with the ‘1.9’ suffix, which means all executables will be suffixed with 1.9: ruby1.9, gem1.9, irb1.9, rake1.9 and so on. This approach is ideal for casual use of two versions side by side. If you don’t care about the details, skip right over the next paragraph.

The industrial approach would be to put ruby in a non standard directory and only add it to your path when you want to use that version (or use the explicit path to invoke executables). To go industrial, you can simply use the --prefix=/usr/local/ruby1.9 option and then drop the --program-suffix argument when you run configure for Ruby. This setup is ideal if you really want to have a bunch of versions living side by side (e.g. all 1.9 versions as well as 1.8.7 in addition to the current 1.8.6).

Actual installation of Ruby 1.9

Pick the most recent version or Ruby 1.9 on the ftp server. At the time of writing, 1.9.1-preview1 is the most recent.

Yep, Ruby 1.9 introduces the very cool stabby lambda syntax. Ruby 1.8’s lambdas couldn’t have optional parameters (unless you fiddled with *args). 1.9’s stabby lambdas can, with a syntax as clean as a simple method definition, as you just experimented.

Now install the gems you use everyday (or kindly make available to your peers) and help make them 1.9 compatible.