Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

When I try to build vim(8.1.0509) with ruby support(--enable-rubyinterp) on macOS Mojave(10.14.1) I get error:

In file included from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby.h:33:
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/ruby.h:24:10: fatal error:
      'ruby/config.h' file not found
#include "ruby/config.h"

I have installed Xcode 10.1.

xcode-select -p
/Applications/Xcode.app/Contents/Developer

Thanks

like image 748
maksimr Avatar asked Nov 03 '18 21:11

maksimr


5 Answers

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

UPDATE: This workaround still works as of 2022. For the commands below, please change version string (e.g., 11.1, ruby 2.6, universal-darwin20, etc.) accordingly to your macOS version environment.


Recent versions of macOS and Xcode (e.g. Catalina 10.15 and Xcode 12.2) 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/ruby
ln -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.0
ln -sf universal-darwin20 universal-darwin19
like image 163
Jongwook Choi Avatar answered Nov 15 '22 09:11

Jongwook Choi


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-build
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile 
rbenv install 2.6.3
rbenv global 2.6.3

Mojave and older

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

xcode-select --install
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
like image 44
ReDetection Avatar answered Nov 15 '22 10:11

ReDetection


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.

edit2: @greg-dubicki mentioned swapping ruby-2.7.2 for ruby-3.0.3: rvm install ruby-3.0.3 and then making it the default: rvm --default use 3.0.3 they also mentioned: As an extra benefit, thanks to the switch from the outdated system Ruby 2 to a current version 3, you will get up to 3 x better performance.

like image 71
Eden Avatar answered Nov 15 '22 10:11

Eden


I had the exact same problem. Could not install gems with native extensions. Running

$ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

failed, because the file did not exist. Looks like Mojave can break the commandline tools.

I fixed it by removing the Xcode commandline tools, installing them again and then installing the missing headers:

$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install
$ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
like image 20
atamanroman Avatar answered Nov 15 '22 09:11

atamanroman


If you are facing this issue in Mac Big Sur, reinstalling CommandLineTools can fix this issue.

sudo rm -rf /Library/Developer/CommandLineTools

xcode-select --install
like image 19
Suraj Poddar Avatar answered Nov 15 '22 09:11

Suraj Poddar