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:
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.hfile is actually missing. So where do I get the file? The fix turns out to be fairly simple.
- Go to the App Store and install XCode (it's free). This may take a while as the install size is 1.6Gb.
- Run XCode. (It must be installed and running to do the next step.)
- From the XCode menu select Preferences -> Download.
- From the list of Components choose Command Line Tools to download and install.