On Xcode 11 / macOS Catalina, the header files are no longer in the old location and the old /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
file is no longer available.
Instead, the headers are now installed to the /usr/include
directory of the current SDK path:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
Most of this directory can be found by using the output of xcrun --show-sdk-path
. And if you add this path to the CPATH
environment variable, then build scripts (including those called via bundle
) will generally be able to find it.
I resolved this by setting my CPATH
in my .zshrc
file:
export CPATH="$(xcrun --show-sdk-path)/usr/include"
After opening a new shell (or running source .zshrc
), I no longer receive the error message mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h and the rubygems install properly.
Note on Building to Non-macOS Platforms
If you are building to non-macOS platforms, such as iOS/tvOS/watchOS, this change will attempt to include the macOS SDK in those platforms, causing build errors. To resolve, either don't set
CPATH
environment variable on login, or temporarily set it to blank when runningxcodebuild
like so:CPATH="" xcodebuild --some-args