Installing Ruby gems that require building native extensions on Snow Leopard

December 18th, 2009 by e-thang Leave a reply »

I haven’t tested this on all “machines” running Snow Leopard, but on the brand new one I had to get today for work, I found that the default Ruby / Gems install doesn’t support installing gems that require building native extensions. The error message I was treated to contained the following:

MacBook-Pro-de-Ethan-Garofolo:~ juanpaco$ sudo gem install thin
Building native extensions. This could take a while...
ERROR: Error installing thin:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install thin
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h

Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.10 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.10/ext/gem_make.out

The solution was hyper-intuitive. Install XCode. Because of course that's the first thing you think of.



  1. I have the had the same problem – I installed XCode yesterday, but still am facing this issue. When you installed XCode, did you need to do anything to get it working?

  2. e-thang says:

    Dang, sorry. No I didn’t. After installing XCode it all just started working.

    Does the error message change for you at all?

  3. Roy Revelch says:

    I know this post is a little old but I thought those who might still be looking for a solution even after you install Xcode could benefit from this.

    So, I got the error mentioned above in the post, and I had Xcode 4.5 installed but it turns out if your on Mountain Lion (10.8.2) then you have to manually install the command line tools from inside Xcode or on the apple developer site.

    Here’s a link for more info on that:

    If that doesn’t, which in my case still didn’t, then this command should do the trick.

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

    It’s basically a symlink to the compiler system (GCC). That should get things working, and hopefully does, if not then maybe someone can push this further for more solutions.

Leave a Reply