Installing Ruby using RVM, Homebrew and Xcode 4.3.

My previous post on installing Ruby 1.9.2 in combination with Xcode 4.3 generated some interest. Since that writeup I did a fresh install of a Lion machine. So here is a follow up post. I think this is the better way to go.

This time, we’ll use Homebrew to fix some of the problems we can run into when using RVM in combination with Xcode 4.3. As you may, or may not, know, Xcode 4.3 introduced a new version of the compiler. This is fine to build Ruby 1.9.3+. Not so for Ruby versions <= 1.9.2. Homebrew makes it very easy to install the correct compiler, needed to build Ruby 1.9.2 and previous versions. Parallel to Xcode 4.3 and it's toolchain. Check if you already have homebrew installed: $ which brew

If all you get is an empty line or an error, you probably need to install Homebrew:
$ /usr/bin/ruby -e "$(/usr/bin/curl -fksSL"

It doesn’t hurt to check your ( existing ) Homebrew installation for possible problems.
The output from the doctor command is very helpful. Read it and act to it.
$ brew doctor

Make absolutely sure you have the latest and greatest:
$ brew update

Optional: handy tab-completion ( DO READ THE ADDITIONAL INFO after installing )
$ brew install bash-completion

Install RVM if you haven’t done so already:
# RVM with latest, stable Ruby
$ curl -L | bash -s stable --ruby

Using 1.9.3 as the default version of Ruby on your system:
# use 1.9.3 as the default Ruby version
$ rvm use 1.9.3-p194 --default

Handy alias pointing to 1.9.3:
# make an alias so you can use: `rvm use 1.9.3` ( without the patch number )
$ rvm alias create 1.9.3 1.9.3-p194

This is where the best part of the post is,
to install Ruby prior to 1.9.3 in combination with XCode 4.3+ on Lion.

Unlock extra formulas for homebrew:
$ brew tap homebrew/dupes

Installs gcc without messing with your Xcode compiler tools:
$ brew install apple-gcc42

Installs the older Ruby 1.8.7 patch 357: closest supported version.
$ rvm install 1.8.7

Installs Ruby 1.9.2-p320
$ rvm install 1.9.2-p320

Now run:
$ rvm list

If all goes well you should see something like:
ruby-1.8.7-p358 [ i686 ]
ruby-1.9.2-p320 [ x86_64 ]
=* ruby-1.9.3-p194 [ x86_64 ]

That’s it. Depending on your machine, this should take approx. 30 minutes to complete every step in this post.

3 thoughts on “Installing Ruby using RVM, Homebrew and Xcode 4.3.”

  1. brew install apple-gcc42 is the magic command. That’s all I needed to start installing older version of Ruby. Thanks for the post, glad I found it.

  2. I agree with the above poster. $ brew install apple-gcc42 was what i was missing. Your post was the missing piece, keep up the good work.

Comments are closed.