Skip to content

Instantly share code, notes, and snippets.

@olivierlacan
Created August 6, 2012 16:12
Show Gist options
  • Save olivierlacan/3276008 to your computer and use it in GitHub Desktop.
Save olivierlacan/3276008 to your computer and use it in GitHub Desktop.
GCC, LLVM and installing old ruby versions

GCC, LLVM and installing old ruby versions

I highly recommend using ruby-install & rbenv to install Ruby versions on your system if you're using OS X.

Homebrew

First you'll need Homebrew (the best package manager for OS X).

ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)

Then simply update Homebrew and install ruby-build & rbenv:

brew update brew install rbenv brew install ruby-build

Ruby 1.9.3+

It's a breeze, simply run rbenv install for the specific version you wish to install.

You can list all existing versions of Ruby made available through ruby-build like this:

ruby-build --definitions

You should see an output like this:

1.8.6-p383
1.8.6-p420
1.8.7-p249
1.8.7-p302
1.8.7-p334
1.8.7-p352
1.8.7-p357
1.8.7-p358
1.9.1-p378
1.9.2-p180
1.9.2-p290
1.9.2-p318
1.9.2-p320
1.9.3-dev
1.9.3-p0
1.9.3-p125
1.9.3-p194
1.9.3-preview1
1.9.3-rc1
2.0.0-dev
jruby-1.6.3
jruby-1.6.4
jruby-1.6.5
jruby-1.6.5.1
jruby-1.6.6
jruby-1.6.7
jruby-1.6.7.2
jruby-1.7.0-preview1
maglev-1.0.0
rbx-1.2.4
rbx-2.0.0-dev
ree-1.8.6-2009.06
ree-1.8.7-2009.09
ree-1.8.7-2009.10
ree-1.8.7-2010.01
ree-1.8.7-2010.02
ree-1.8.7-2011.03
ree-1.8.7-2011.12
ree-1.8.7-2012.01
ree-1.8.7-2012.02

So let's install the latest and greatest version:

rbenv install 1.9.3-p194

Downloading http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz...
Installing yaml-0.1.4...
Installed yaml-0.1.4 to /Users/olivierlacan/.rbenv/versions/1.9.3-p194
Downloading http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz...
Installing ruby-1.9.3-p194...
Installed ruby-1.9.3-p194 to /Users/olivierlacan/.rbenv/versions/1.9.3-p194

Oh, and if you're going to be using 1.9.3, you might want to check out the Falcon patch.

Ruby 1.9.2 and older

Ruby 1.9.3 can be compiled using LLVM, but that's not the case with Ruby 1.9.2 and older which means you'll need a GCC compiler or rbenv will yell this at you when you try to install 1.9.2 for instance.

rbenv install 1.9.2-p320

ERROR: This package must be compiled with GCC, but ruby-build couldn't
find a suitable `gcc` executable on your system. Please install GCC
and try again.

DETAILS: Apple no longer includes the official GCC compiler with Xcode
as of version 4.2. Instead, the `gcc` executable is a symlink to
`llvm-gcc`, a modified version of GCC which outputs LLVM bytecode.

For most programs the `llvm-gcc` compiler works fine. However,
versions of Ruby older than 1.9.3-p125 are incompatible with
`llvm-gcc`. To build older versions of Ruby you must have the official
GCC compiler installed on your system.

TO FIX THE PROBLEM: Install the official GCC compiler using these
packages: https://github.com/kennethreitz/osx-gcc-installer/downloads

You will need to install the official GCC compiler to build older
versions of Ruby even if you have installed Apple's Command Line Tools
for Xcode package. The Command Line Tools for Xcode package only
includes `llvm-gcc`.

As this very useful message indicates, the Command Line Tools for Xcode package is not going to be useful compiling some things like older Rubies. I've also encountered similar issues with other binaries.

Kenneth Reitz' OSX GCC Installer has consistently been the best Xcode-free solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment