Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker for Mac - mkmf.rb can't find header files for ruby

Tags:

docker

ruby

I updated XCode on my Mac and since then when starting Docker using docker-sync-stack start I get this error message:

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

I tried installing ruby with this: brew install rbenv ruby-build but this does not change anything.

Does anybody know how I can fix it?

Thanks!

like image 664
Torben Avatar asked Sep 23 '17 08:09

Torben


4 Answers

For Xcode 11 on macOS 10.14, this can happen even after installing Xcode and installing command-line tools and accepting the license with

sudo xcode-select --install
sudo xcodebuild -license accept

The issue is that Xcode 11 ships the macOS 10.15 SDK which includes headers for ruby2.6, but not for macOS 10.14's ruby2.3. You can verify that this is your problem by running

ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'

which on macOS 10.14 with Xcode 11 prints the non-existent path

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0

However, Xcode 11 installs a macOS 10.14 SDK within /Library/Developer/CommandLineTools/SDKs/MacOS10.14.sdk. It isn't necessary to pollute the system directories by installing the old header files as suggested in other answers. Instead, by selecting that SDK, the appropriate ruby2.3 headers will be found:

sudo xcode-select --switch /Library/Developer/CommandLineTools
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'

This should now correctly print

/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0

Likewise, gem install should work while that SDK is selected.

To switch back to using the current Xcode 11 SDK, use

sudo xcode-select --switch /Applications/Xcode.app
like image 80
joki Avatar answered Nov 15 '22 08:11

joki


None of the other solutions worked for me, here's what I ran to resolve the issue on Mac OS 10.14.x:

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
like image 28
ryanpcmcquen Avatar answered Nov 15 '22 07:11

ryanpcmcquen


When upgrading XCode you need to install the Command-Line Tools and additionally accept the terms and conditions:

sudo xcode-select --install

Then:

sudo xcodebuild -license
like image 36
tadman Avatar answered Nov 15 '22 08:11

tadman


As of Xcode 11, it seems like the ruby development headers are no longer included, so you will need to manually install them outside of Xcode Command Line Tools.

E.g. for me using rbenv i did

rbenv install 2.6.4
rbenv global 2.6.4
eval "$(rbenv init -)"

Then ran bundle install and everything worked as expected.

like image 19
bdorfman Avatar answered Nov 15 '22 07:11

bdorfman