HOWTO Fix Ruby on Mountain Lion
Ruby on Mountain Lion is pretty much useless right now.
The only good news is that (I think) it only affects ruby 2.0.
There are plenty of tutorials floating around the web to get around this, but I found them all to be incomplete. Hopefully any poor soul who finds themself in the same position will find this post helpful. ("I've been stuck in this hole before, and I know the way out.")
I've always been in the habit of building ruby from source. Apple still ships 1.8.7, and it's only been in the last six months or so that Linux vendors have been packaging a 1.9 ruby. I don't bother with rvm or it's equivalents, because I've found they just don't work.
To build ruby, you'll need make and gcc, which are now missing from the standard OS X install. To get them, you can download the full Xcode package or a smaller command line utilities image from Apple. Either way, you'll need an Apple ID and a good book to read while you wait for the download.
With the command line tools in place, you can now build ruby the usual way:
% tar -xvf ruby-2.0.0-p0.tar.gz
% cd ruby-2.0.0-p0
% ./configure
% make
% make install
Everything looks groovy, until you try to use ruby's package manager and discover that gem doesn't have SSL support compiled in.
With all that text flying by it's easy to miss the relevant error message from make:
Ignore OpenSSL broken by Apple.
Please use another openssl. (e.g. using `configure --with-openssl-dir=/path/to/openssl')
Failed to configure openssl. It will not be installed.
So here's how to actually fix it:
Install openssl from source. Then configure ruby to point to the new local openssl installation:
% ./configure --with-openssl-dir=/usr/local/ssl/
The configure script will complain that this is an invalid option. But it will build correctly anyway. (This is apparently a known ruby bug, as opposed to a known Apple bug. You could be angry about how absurd this has become, but it's better to just laugh it off. We're almost done.)
Run make again:
% make && make install
Be thankful that Ruby builds quickly. In fact, it will probably build in less time than it took to download the command line tools.
Thanks Apple. You stay classy.