Last Updated: February 25, 2016
·
2.052K
· johnnyrodgers

Installing ruby and gems with native extensions on OS X Mavericks

I previously posted about how to upgrade your ruby environment for OS X Mavericks: https://coderwall.com/p/5awmcq. I was helping a friend update his environment using the same steps, but we kept running into issues building gems with native extensions.

This was apparently due to a conflict between RVM (ruby version manager) and the installed version of GCC.

After a lot of dead ends attempting to get the gem bundle to install, I eventually stumbled on this SO question: http://stackoverflow.com/questions/15204141/adding-usr-bin-gcc-4-2-to-path-installing-ruby.

The only answer (at time of writing) was to run:

rvm requirements

This spills out a ton of useful information about the rvm config. In the case of the machine I was working on, there were a variety of things missing for rvm to successfully install ruby and compile gems.

First I removed the existing version of ruby:

rvm remove ruby-1.9.3

Then followed the detailed instructions returned by running rvm requirements. In my case:

brew install libksba

rvm install 1.9.3
rvm system ; rvm gemset export system.gems ; rvm 1.9.3 ; rvm gemset import system.gems

Reopen your terminal windows. Then install gcc-4.2:

Xcode and gcc:

Right now Ruby requires gcc to compile, but Xcode 4.2 and later no longer ship with gcc. Instead they ship with llvm-gcc (to which gcc is a symlink) and clang, neither of which are supported for building Ruby. Xcode 4.1 was the last version to ship gcc, which was /usr/bin/gcc-4.2.

Xcode 4.1 and earlier:
- Ruby will build fine.

Xcode 4.2 and later (including Command Line Tools for Xcode):
- If you have gcc-4.2 (and friends) from an earlier Xcode version, Ruby will build fine.
- If you don't have gcc-4.2, you have two options to get it:
 * Install apple-gcc42 from Homebrew
 * Install osx-gcc-installer

  Homebrew:

  If you are using Homebrew, you can install the apple-gcc42 and required libraries from homebrew/dupes:

      brew update
      brew tap homebrew/dupes
      brew install autoconf automake apple-gcc42
      rvm pkg install openssl

  Xcode 4.2+ install or/and Command Line Tools for Xcode is required to provide make and other tools.

  osx-gcc-installer:

  If you don't use Homebrew, you can download and install osx-gcc-installer: https://github.com/kennethreitz/osx-gcc-installer.

  Warning: Installing osx-gcc-installer on top of a recent Xcode is known to cause problems, so you must uninstall Xcode before installing osx-gcc-installer. Afterwards you may install Xcode 4.2+ or Command Line Tools for Xcode if you desire.

Further information: http://stackoverflow.com/questions/8032824/cant-install-ruby-under-lion-with-rvm-gcc-issues

After running these steps, ruby was installed cleanly and bundler was able to install gems with native extensions. There are many questions on SO and various fixes recommended, but these were the steps that worked for me.