macOS Mojave 'ruby/config.h' file not found macOS Mojave 'ruby/config.h' file not found ruby ruby

macOS Mojave 'ruby/config.h' file not found


macOS Catalina

Issue reappeared in Catalina and I wasn't able to spot this package in the Developer SDK. Until better solution found, I was able to workaround this with rubyenv: https://github.com/orta/cocoapods-keys/issues/198#issuecomment-510909030

brew install rbenv ruby-buildecho 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile rbenv install 2.6.3rbenv global 2.6.3

Mojave and older

This answer helped me: https://stackoverflow.com/a/53194299/2105993

xcode-select --installopen /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg


Catalina, Big Sur, etc. (As of 2020 and 2021)

Recent versions of macOS and Xcode (e.g. Catalina 10.15 and Xcode 12.2) definitely have this broken. Reinstalling Xcode and xcode-select --install did not help for me at all (the solutions already posted seem to be outdated). I did not want to use rvm because it may cause some annoying problems.

I did a workaround by manually making a symbolic link:

cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/rubyln -sf ../../../../Headers/ruby/config.h

where ruby/config.h can be found at:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/Headers/ruby/config.h.

You should change SDK versions (e.g. 11.1 in the above example) accordingly to your current xcode installation.

It is also very likely that one runs into another error where .../universal-darwin19/ruby/config.h cannot be found (Commonmarker gem cannot be installed (needed for jekyll) macos). It can be quick-fixed as follows:

cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0ln -sf universal-darwin20 universal-darwin19


On macOS Catalina
After installing and uninstalling the developer tools multiple times, this is the only thing that worked for me:

First install the Ruby Version Manager rvm:

curl -L https://get.rvm.io | bash -s stable

Then install the latest version of ruby:

rvm install ruby-2.7.2

Finally try again to install the cocoapods:

sudo gem install cocoapods

(from this answer: https://stackoverflow.com/a/65033418/3605761)

edit: may need rvm reinstall ruby-2.7.2 instead of rvm install ruby-2.7.2 at step 2.