Install Native Ruby Gem in Mountain Lion Preview


Filed under: ruby, os x, gem, mountain lion

In Preview of OS X Mountain Lion, XCode has been distributed as a .app package verses the traditional installer. Also the Commandline Tools are not installed by default. Commandline Tools contains cc/gcc that you will need.

After download the preview of XCode 4.4, drop it to the Application directory.

Open XCode and cmd + , to open Preferences panel where you can install Commandline Tools:

Now in shell you should be able to locate cc and locate gcc

Now if you try to gem install hpricot or any gem that requires native extension (c), you may encounter problems looks like this:

checking for main() in -lc... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:

If you cat the mkmf.log, you may see something like this:

“gcc-4.2 -o conftest ….”

So the fix is not to add configuration options but to simply create sym link of gcc-4.2:

ln -s /usr/bin/gcc /usr/bin/gcc-4.2