Site Navigation

Feb 11, 2013

Can't install C compiled Ruby Gem on OS X Mountain Lion

OS X picture
Problem: I can't install any Ruby Gem which requires compilation with C. For example, when I try to install the RedCloth Textile processor I get the following error message:

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

Note that I am using Ruby 1.8.7 which is the default for Lion and Mountain Lion.

Solution: Well the problem is straightforward, you are getting the error message because the ruby.h file is actually missing. So where do I get the file? The fix turns out to be fairly simple.
  1. Go to the App Store and install XCode (it's free). This may take a while as the install size is 1.6Gb.
  2. Run XCode. (It must be installed and running to do the next step.)
  3. From the XCode menu select Preferences -> Download.
  4. From the list of Components choose Command Line Tools to download and install.
Once the installation is complete, you should have the files you need to install Ruby Gems. Enjoy!
Post a Comment

Favorite Links Feed