Ever since Xcode 4.2, which removed gcc in favor of clang, ruby 1.8 (and some versions of 1.9, and many gems with native code) wouldn’t compile or wouldn’t work correctly when compiled. There was a workaround, in the form of the osx-gcc-installer. It was a little bit hacky – but the work and the author, Kenneth Reitz, were basically responsible for making the command-line tools package happen.
Now it’s very easy to get a full compiler environment, including pure gcc (rather than clang’s emulation of it), that can build all variants of ruby and gems without an issue. The trivial process goes like this:
First, download and install the Command Line Tools for Xcode. These can be installed either through Preferences > Downloads > Components in the full Xcode 4.3 install, or by downloading and installing the standalone package.
Next, install homebrew, a fantastic package manager for OS X. Run
brew update to make sure it’s fully up to date.
Next, add the homebrew “dupes” repository (or “keg”), some necessary recipes for installation, and the real gcc 4.2:
brew tap homebrew/homebrew-dupes brew install autoconf automake brew install apple-gcc42
Now you can safely build and install various rubies. rvm is a great way to do this without stepping on the system-installed ruby:
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer) source ~/.rvm/scripts/rvm rvm get head rvm install 1.8.7 rvm install 1.9.3-head