And among the dreams of the days that were
I find my lost youth again.
And the strange and beautiful song,
The groves are repeating it still:
'A boy's will is the wind's will,
And the thoughts of youth are long, long thoughts.'-- Henry Wadsworth Longfellow, My Lost Youth
Tonight I surrendered another substantial chunk of my life to the hell that is installing Ruby on Rails on Mac OSX Lion.
This isn't the first time I've had to waste hours of my life on an epic, yak-shaving expedition in the name of working with Rails. In fact, it seems that every time I want to do a project with Rails, I'm forced by some gem, package or dependency to re-plumb substantial portions of my system's core infrastructure.
Even if I didn't care about the time lost to this kind of garbage, I very much do care about having to override compilers, replace core system libraries, or otherwise monkey around with parts of my system that a web framework shouldn't have to touch. It's a total mess. I don't know what the solution is, but I know that I never have to do this kind of crap with Python or C++.
...but I'll leave the ranting for another day. In the interest of saving someone else the time I had to spend tonight, here's a process that will work for getting Ruby Enterprise Edition (aka "REE") working on a fairly squeaky-clean Mac OSX Lion installation, using RVM and Homebrew:
Problem 1: REE doesn't build with Lion's installed version of GCC
The first problem you run into, if you just try the naive RVM installation approach on Lion (rvm install ree), is that Apple's choice of installing only an LLVM-based version of gcc in XCode 4.3 breaks the build of many software packages (including Ruby Enterprise Edition). There has been much gnashing of teeth about this choice. Personally, I say a "plague on both your houses" -- there are plenty of packages that compile cleanly on Lion (including, as of a few days ago, the reference Ruby interpreter itself), so it clearly isn't impossible to make REE work, but at the same time, Apple could also be a bit less difficult about using bleeding-edge compiler technology. That said, I'm absolutely not going to replace my system's default compiler just so that I can get a non-standard version of Ruby installed on my dev machine. (That's non-negotiable, in my opinion, but it was the Ruby community's standard response to this problem for months. Grumble.)
Fortunately, there's a solution: it's possible to use to install gcc-4.2 without having to resort to replacing XCode. If you don't have Homebrew installed or if you don't trust someone else to build your compilers, you can compile gcc by hand, using Apple's own source tarballs. But if you have Homebrew, you can also use homebrew-alt to get the necessary non-LLVM gcc binaries. (Why can't you get a version of gcc directly from Homebrew? Good question. As far as I can tell, the answer involves even more "opinionated" development. But I digress.) The relevant command is:
brew install autoconf automake https://raw.github.com/adamv/homebrew-alt/master/duplicates/apple-gcc42.rb
This will install the autotools (which are necesary for building later packages), as well as a non-LLVM version of GCC 4.2 (if you're using a standard Homebrew install, this compiler will be located in /usr/local/bin/gcc-4.2 after installation.) Once we have this, we're theoretically capable of building REE...just not with RVM. We have another problem:
Problem 2: RVM gets confuzzled about the right GCC to use
Fortunately, this problem is relatively easy to solve. First, be sure to clean up any previous failed attempts at installing REE:
rvm remove ree
Next, update your RVM, to be sure that it has awareness of the peculiarities of installations on Xcode 4.2 and gcc-4.2 systems:
rvm update
Next, force RVM to use your shiny new copy of gcc-4.2 by overriding the CC environment variable:
export CC=/usr/local/bin/gcc-4.2
Finally, build REE using RVM:
rvm install ree
This should grind away for a little while, but ultimately succeed. If you get patch failures or other bizarre build errors, you've almost certainly set your $CC to the wrong value. Ensure that it's pointing at the version of gcc that you just installed (one easy way to do this is to run $CC, and check that the output is 'i686-apple-darwin11-gcc-4.2.1: no input files'. If, instead, the output has a bunch of garbage about XCode-this and Apple-that, and references LLVM, you're still using the Xcode compiler.)
Hopefully this post saves you some precious hours, and allows you to just Get Shit Done, without having to become a pawn in the ongoing battle between Apple and the Opinionated Developers, neither of whom are really optimizing for your time.