Monday, February 13, 2012

Ruby 1.9.3 via RVM on Mac OSX Lion: Success Story

Ruby 1.9.3: freakin' fast bro!
That fast!

After a long time away from Rails and Ruby, I roll up my sleeves today and try to figure out what I’ve missed lately:

  • first, Rails 3.2 proves to be engineered to work faster in dev mode, by now incorporating the Active Reload gem by default.
  • then reading some more, Ruby 1.9.3 bubbles up — it’s freaking fast bro!

Great news, time for our good old friend RVM:

  1. $ rvm get head
  2. $ rvm reload
  3. $ rvm install 1.9.3

But wait…

The Problem

Installing Ruby from source to: /Users/marius/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)...

ruby-1.9.3-p0 - #fetching 
ruby-1.9.3-p0 - #extracted to /Users/marius/.rvm/src/ruby-1.9.3-p0 (already extracted)
Fetching yaml-0.1.4.tar.gz to /Users/marius/.rvm/archives
Extracting yaml-0.1.4.tar.gz to /Users/marius/.rvm/src
Configuring yaml in /Users/marius/.rvm/src/yaml-0.1.4.
Compiling yaml in /Users/marius/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/marius/.rvm/usr
ruby-1.9.3-p0 - #configuring 
ERROR: Error running ' ./configure --prefix=/Users/marius/.rvm/rubies/ruby-1.9.3-p0 --enable-shared --disable-install-doc --with-libyaml-dir=/Users/marius/.rvm/usr ', please read /Users/marius/.rvm/log/ruby-1.9.3-p0/configure.log
ERROR: There has been an error while running configure. Halting the installation.

The installer fails with an error message including checking whether the C compiler works... no even with Xcode 4.2 available.

The Wrong Path

Checked configure.log, found all the questions on SO and went for the fast solution:

$ rvm reinstall 1.9.3 --with-gcc=clang

which didn’t work for me!

The Solution

Following mpapis’ advice, I downloaded the GCC Installer for OSX 10.7+, v2, by Kenneth Reitz, and a simple

$ rvm reinstall 1.9.3

did the trick! So I was happy to jump to the next step:

$ rvm --default use 1.9.3

The Bonus

Downloading and installing the massive Xcode tool suite (2.5GB!!!) is a huge hassle if you just want GCC and related tools.

The osx-gcc-installer includes the essential compilers:

  • GCC
  • LLVM
  • Clang
  • Developer CLI Tools (purge, etc)
  • DevSDK (headers, etc)

Therefore, since I’m not planning to use Xcode for other reasons, I simply removed it:

$ sudo /Developer/Library/uninstall-devtools –mode=all

If the Rails install fails with a message along these lines:

ERROR:  Error installing rails:
 ERROR: Failed to build gem native extension.

        /Users/marius/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb
creating Makefile

make
sh: make: command not found
don't worry, just run the GCC Installer once again.
Success!
©the-chosen-pessimist