Hello, I’m a web craftsman with a passion for the modern web. I build web applications and play with social services and communities.

February 25, 2012 at 5:17 pm

Since Xcode 4.2 Apple doesn’t ship a normal GCC anymore, but instead packages LLVM. While it was possible to compile Ruby with LLVM before, the result was error prone. Not anymore! Since 1.9.3-p125 Ruby is fully compatible with LLVM and here is how you can install it without the need of any additional GCC installation.

I’m going to use rbenv and ruby-build in the progress. This way everything is installed in ~/.rbenv and you won’t need any administrator privileges.

  1. Install Xcode 4.3 or the new stand-alone command line tools
  2. Install rbenv and ruby-build
    # install rbenv
    $ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
    $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile
    $ echo 'eval "$(rbenv init -)"' >> .bash_profile
    # You may be using Zsh or any other shell.
    # I presume you know how to adopt the previous two lines then.
    # install ruby-build
    $ mkdir -p ~/.rbenv/plugins
    $ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
    # reload bash (alternatively close and re-open Terminal)
    $ source ~/.bash_profile
  3. Compile Ruby 1.9.3-p125 and make default ruby
    $ env CC=/usr/bin/gcc rbenv install 1.9.3-p125
    $ rbenv global 1.9.3-p125
    $ rbenv rehash
  4. Done. Check everything is ok now
    $ ruby -v
    # => ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]

Sweet. Leave a note in the comments if this helped you. Happy coding!