23

Ever since upgrading to Yosemite, I get this error trying to build anything that includes ruby.h:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
         ^
1 error generated.
make[1]: *** [objects/if_ruby.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [first] Error 2

And sure enough, /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/config.h is indeed missing.

$ ls -laF /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/
total 72
drwxr-xr-x  21 root  wheel    714 Jul 29 21:56 ./
drwxr-xr-x   5 root  wheel    170 Jul 29 21:56 ../
drwxr-xr-x   7 root  wheel    238 Jul 29 21:56 backward/
-rw-r--r--   2 root  wheel   3360 Sep 21 15:25 debug.h
-rw-r--r--   2 root  wheel   5553 Sep 21 15:25 defines.h
-rw-r--r--   2 root  wheel    881 Sep 21 15:25 digest.h
-rw-r--r--   2 root  wheel   7628 Sep 21 15:25 dl.h
-rw-r--r--   2 root  wheel  14123 Sep 21 15:25 encoding.h
-rw-r--r--   2 root  wheel  32904 Sep 21 15:25 intern.h
-rw-r--r--   2 root  wheel   5869 Sep 21 15:25 io.h
-rw-r--r--   2 root  wheel   4522 Sep 21 15:25 missing.h
-rw-r--r--   2 root  wheel  37617 Sep 21 15:25 oniguruma.h
-rw-r--r--   2 root  wheel   1502 Sep 21 15:25 re.h
-rw-r--r--   2 root  wheel    890 Sep 21 15:25 regex.h
-rw-r--r--   2 root  wheel  49734 Sep 21 15:25 ruby.h
-rw-r--r--   2 root  wheel   4651 Sep 21 15:25 st.h
-rw-r--r--   2 root  wheel    374 Sep 21 15:25 subst.h
-rw-r--r--   2 root  wheel   1102 Sep 21 15:25 thread.h
-rw-r--r--   2 root  wheel   2139 Sep 21 15:25 util.h
-rw-r--r--   2 root  wheel   1968 Sep 21 15:25 version.h
-rw-r--r--   2 root  wheel   1794 Sep 21 15:25 vm.h

Did the install accidentally a file? Does Yosemite just ship with a busted Ruby header file set?

What's the best way to fix this? Can I just unpack the source code in there to get the right headers?

Kampai
  • 22,848
  • 21
  • 95
  • 95
isaacs
  • 16,656
  • 6
  • 41
  • 31
  • Did you reinstall the Xcode tools? System upgrades have been known to force that need. – the Tin Man Oct 17 '14 at 23:16
  • I reinstalled the Xcode command line tools, but still don't have a ruby/config.h – isaacs Oct 18 '14 at 00:16
  • 1
    I don't think you have the correct Xcode installed. Note the directory in the path: `MacOSX10.9.sdk` I'd expect to see something about 10.10. – CDub Oct 18 '14 at 00:32
  • CDub! Awesome. I reinstalled Xcode 6.0.1, and now it seems to work, and pulls ruby.h from a completely different location. Thanks for the tip! – isaacs Oct 18 '14 at 16:28

9 Answers9

18

One note on this: I ran into this problem after upgrading to "OS X El Capitan". I installed the command line tools by running 'xcode-select --install'. After that, my ruby build environment started working again.

Jesus Ruiz
  • 1,377
  • 11
  • 5
17

For those who already had Xcode installed from the Apple developers site, running xcode-select --install doesn't work, since it will say that Xcode is already installed (Xcode already comes with the CommandLineTools bundled).

In my case, I fixed it by downloading the corresponding CommandLineTools from the same place, executing it, then going to /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg and executing it too.

Dielson Sales
  • 1,715
  • 1
  • 20
  • 25
16
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby
sudo ln -s ../universal-darwin15/ruby/config.h ./config.h

updates Nicholas Tsipanov's answer from 2014-10-18.

John Chew
  • 319
  • 2
  • 4
  • This is not working for me on OS X El Capitan 10.11.6; No such file or directory. I had to run `'xcode-select --install'` as described by Jesus instead. – user5359531 Sep 30 '16 at 19:24
  • Maybe your `MacOSX10.11.sdk` or `universal-darwin15` needs to be the correct path. It worked for me after ensuring correct path. – Taku Nov 14 '16 at 06:40
12

I got the same error, but installed "Command Line Tools (OS X 10.10) for Xcode - Xcode 6.1" and installing worked fine after that.

Emil Stenström
  • 13,329
  • 8
  • 53
  • 75
6

If you use Homebrew, brew install ruby is a fast workaround (it gets you a brand new ruby installation distinct from the one from Xcode).

rsenna
  • 11,775
  • 1
  • 54
  • 60
  • 1
    @AboozarRajabi `echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc` if you are on bash or some other shell where you will want to pipe it elsewhere. – Jadam Nov 07 '18 at 16:43
  • Thanks, I solved the problem by upgrading Ruby and also Rails to the latest versions (missing gems are reinstalled) – Aboozar Rajabi Nov 07 '18 at 21:15
  • Wouldn't this potentially break other programs that assume you're using the version that comes with the OS? – Dielson Sales Dec 09 '18 at 03:44
4

Try this:

cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby
sudo ln -s ../universal-darwin13/ruby/config.h ./config.h
1

Xcode got messed up in the upgrade somehow.

I opened Xcode (which I never do otherwise) and it complained about all sorts of missing components. So I let it go ahead and fix itself, and now all is well.

Props to CDub in the comments on OP for pointing to this as a potential source of weirdness.

isaacs
  • 16,656
  • 6
  • 41
  • 31
1

I am running Mojave 10.14.6. The answer here fixed the subject issue for me: https://stackoverflow.com/a/58084238/284651

Solution:

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
sudo xcodebuild -license accept
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg 
spdrman
  • 1,372
  • 2
  • 13
  • 18
0

Fixed by pointing to correct path for Xcode developer tools.

Error before (Note the path to Xcode711.app instead of Xcode.app)

/Applications/Xcode711.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/ruby.h:24:10:

Ran

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
Neo
  • 4,640
  • 5
  • 39
  • 53