brew: Homebrew development commands fail to install some gems on Mojave on Xcode >10

What you were trying to do (and why)

Run brew audit on any formula, e.g., brew audit gmp.

What happened (include command output)

The error is Gem::Ext::BuildError: ERROR: Failed to build gem native extension. Full output below:

Command output
  
Fetching gem metadata from https://rubygems.org/........
Using ast 2.4.0
Using bundler 2.0.1
Fetching json 2.1.0
Using docile 1.3.1
Using simplecov-html 0.10.2
Using tins 1.20.2
Using thor 0.19.4
Using diff-lcs 1.3
Fetching hpricot 0.8.6
Fetching jaro_winkler 1.5.2
Installing jaro_winkler 1.5.2 with native extensions
Installing json 2.1.0 with native extensions
Installing hpricot 0.8.6 with native extensions
Using mustache 1.1.0
Using parallel 1.13.0
Using parser 2.6.0.0
Using powerpack 0.1.2
Using rainbow 3.0.0
Fetching rdiscount 2.2.0.1
Installing rdiscount 2.2.0.1 with native extensions
Using rspec-support 3.8.0
Using ruby-progressbar 1.10.0
Using unicode-display_width 1.4.1
Using term-ansicolor 1.7.1
Using parallel_tests 2.27.1
Using rspec-core 3.8.0
Using rspec-expectations 3.8.2
Using rspec-mocks 3.8.0
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/json-2.1.0/ext/json/ext/generator /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20190119-5767-u1kt7r.rb extconf.rb creating Makefile

current directory: /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/json-2.1.0/ext/json/ext/generator make “DESTDIR=” clean

current directory: /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/json-2.1.0/ext/json/ext/generator make “DESTDIR=” compiling generator.c In file included from generator.c:1: In file included from ./…/fbuffer/fbuffer.h:5: 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” ^~~~~~~~~~~~~~~ 1 error generated. make: *** [generator.o] Error 1

make failed, exit code 2

Gem files will remain installed in /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/json-2.1.0 for inspection. Results logged to /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-18/2.3.0/json-2.1.0/gem_make.out

An error occurred while installing json (2.1.0), and Bundler cannot continue. Make sure that gem install json -v '2.1.0' --source 'https://rubygems.org/' succeeds before bundling.

In Gemfile: coveralls was resolved to 0.8.22, which depends on simplecov was resolved to 0.16.1, which depends on json

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/jaro_winkler-1.5.2/ext/jaro_winkler /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20190119-5767-4udt80.rb extconf.rb creating Makefile

current directory: /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/jaro_winkler-1.5.2/ext/jaro_winkler make “DESTDIR=” clean

current directory: /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/jaro_winkler-1.5.2/ext/jaro_winkler make “DESTDIR=” make: *** No rule to make target /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18/ruby/config.h', needed by adj_matrix.o’. Stop.

make failed, exit code 2

Gem files will remain installed in /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/jaro_winkler-1.5.2 for inspection. Results logged to /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-18/2.3.0/jaro_winkler-1.5.2/gem_make.out

An error occurred while installing jaro_winkler (1.5.2), and Bundler cannot continue. Make sure that gem install jaro_winkler -v '1.5.2' --source 'https://rubygems.org/' succeeds before bundling.

In Gemfile: rubocop was resolved to 0.63.0, which depends on jaro_winkler Error: cannot load such file – rubocop Please report this bug: https://docs.brew.sh/Troubleshooting /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require' /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require’ /usr/local/Homebrew/Library/Homebrew/style.rb:21:in check_style_impl' /usr/local/Homebrew/Library/Homebrew/style.rb:14:in check_style_json’ /usr/local/Homebrew/Library/Homebrew/dev-cmd/audit.rb:149:in audit' /usr/local/Homebrew/Library/Homebrew/brew.rb:102:in <main>’

Reproducibility

At first, I thought it was only a problem on my machine, and linked to me having /usr/include populated under Mojave (which is not supposed to happen) due to a faulty CLT update from Apple.

However, I have now removed and reinstalled both CLT and Xcode, and nuked that faulty include directory, meaning I now have a “normal” Mojave system, and it still happens. Other users have been reporting it, for example here https://github.com/Homebrew/homebrew-core/pull/36156 and there https://github.com/Homebrew/homebrew-core/pull/35934, so there definitely is something to fix here.

Why do I believe it is a brew issue, and not a ruby issue? I have never in my life used Ruby outside of brew, so if something messed it up, it must be brew-related 😢

Have I tried to fix it?

I have run rm -rf /usr/local/Homebrew/Library/Homebrew/vendor/bundle ~/.gem (per @MikeMcQuaid’s advice), then brew tests. The tests fail with the same error as above.

Additional info

$ brew config
HOMEBREW_VERSION: 1.9.2-35-gcf32929
ORIGIN: https://github.com/Homebrew/brew
HEAD: cf32929116b2d5193bad9d78cc627d097cf7612c
Last commit: 28 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: b7dc0849fc14d3914073e89653442f6e1ce98886
Core tap last commit: 15 hours ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_BINTRAY_KEY: set
HOMEBREW_BINTRAY_USER: fxcoudert
HOMEBREW_DEV_CMD_RUN: 1
HOMEBREW_LOGS: /Users/fx/Library/Logs/Homebrew
HOMEBREW_NO_ANALYTICS_THIS_RUN: 1
CPU: dodeca-core 64-bit kabylake
Homebrew Ruby: 2.3.7 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Clang: 10.0 build 1000
Git: 2.17.2 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.54.0 => /usr/bin/curl
Java: 1.8.0_144
macOS: 10.14.2-x86_64
CLT: 10.1.0.0.1.1539992718
Xcode: 10.1
XQuartz: 2.7.11 => /opt/X11
$ xcode-select --print-path
/Applications/Xcode.app/Contents/Developer
$ ruby --version
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 10
  • Comments: 58 (26 by maintainers)

Most upvoted comments

This solved it for me:

$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install
$ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

I don’t have Xcode installed, I only had the CLI Tools.

My current workaround:

rm -rf /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/
brew vendor-install ruby

Using brew vendor-install ruby alone is not enough.

I think there is some incompatibility between macOS’ default Ruby (and probably portable-ruby from Homebrew’s) and its native extensions.

Yes, see: https://github.com/Homebrew/homebrew-cask/issues/52775#issuecomment-444545063 https://openradar.appspot.com/46465917. Apple are aware of it and are working on a fix. I’m not sure why this doesn’t affect everyone.

@ryanpropst1 I used the command line to remove the files.

cd /usr/local/Homebrew/Library/Homebrew/vendor/ to move into the vendor directory.

rm portable-ruby-version to delete the version file

rm -rf portable-ruby to delete the portable ruby installation. Be very careful with this command as it can cause a lot of damage if there is a typo.

rm -rf bundle/ruby/2.3.0 to delete all the ruby gems etc. Again, be careful. These files will be rebuilt when you run a brew audit command.

Finally, run brew audit <formula> where <formula> is the name of a homebrew formula (I was using the ldc formula, but I believe any formula will work). This will download and build all the ruby gems again.

@JuPlutonic Not exactly, instead I put ruby 2.6.0 pulled from rvm and set HOMEBREW_RUBY_PATH to the ruby (from rvm) path.

When I did not put HOMEBREW_DEVELOPER flag to env, Homebrew keeps using its portable-ruby (I don’t know exactly why) so I simply put HOMEBREW_DEVELOPER=true.

I think there is some incompatibility between macOS’ default Ruby (and probably portable-ruby from Homebrew’s) and its native extensions.

Success. 😃

I had to delete the portable-ruby directory and portable-ruby-version file at /usr/local/Homebrew/Library/Homebrew/vendor/ and then I deleted the entire directory at /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/

Then I ran the “brew audit <formula>” command. This causes all the ruby gems to be reinstalled which recreates the /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/ directory. This time the gems are built using the system ruby, so the incompatible library error is resolved.

brew doctor said that I had uncommitted modifications to homebrew, so I took its advice and ran the command

cd /usr/local/Homebrew/Library && git stash && git clean -d -f

Now brew doctor is happy, and I can audit a formula. My brew config now reports:

Homebrew Ruby: 2.3.7 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby

instead of the the portable-ruby as I had before.

I again have a working homebrew system.

@VonUniGE thanks for updating ldc

No, I didn’t try your workaround. I had tried the “brew vendor-install ruby” earlier, but without the file deletions.

After that I started digging into the actual errors being reported and then discovered the incorrect system headers for ruby. It turns out there is a fix for that issue as described at https://stackoverflow.com/questions/53135863/macos-mojave-ruby-config-h-file-not-found. The answer provided by atamanroman https://stackoverflow.com/users/366299/atamanroman worked. It removes the CommandLineTools, and reinstalled them to replace a missing Package file, and then runs the package file to correct the System ruby headers by creating the missing universal-darwin18 directory. The commands are copied here for other that run into this issue:

$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install
$ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

After this all the gems installed correctly when I ran brew audit.

Unfortunately I got another error during “brew audit” as shown below.

Error: incompatible library version - /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/jaro_winkler-1.5.2/lib/jaro_winkler/jaro_winkler_ext.bundle
Please report this bug:
  https://docs.brew.sh/Troubleshooting
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.7/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.7/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/jaro_winkler-1.5.2/lib/jaro_winkler.rb:6:in `<top (required)>'
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.7/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.7/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/rubocop-0.65.0/lib/rubocop/string_util.rb:3:in `<top (required)>'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/rubocop-0.65.0/lib/rubocop.rb:21:in `require_relative'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.3.0/gems/rubocop-0.65.0/lib/rubocop.rb:21:in `<top (required)>'
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.7/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.7/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/Homebrew/Library/Homebrew/style.rb:21:in `check_style_impl'
/usr/local/Homebrew/Library/Homebrew/style.rb:14:in `check_style_json'
/usr/local/Homebrew/Library/Homebrew/dev-cmd/audit.rb:112:in `audit'
/usr/local/Homebrew/Library/Homebrew/brew.rb:102:in `<main>'

I filed a bug report as requested, but I think this may be due to the previous “brew vendor-install ruby” that I did. I’m still not sure what that command does, and the brew help isn’t that helpful.

Denniss-iMac:~ dennis$ brew help vendor-install
Usage: brew vendor-install [target]

Install Homebrew's portable Ruby.

Before and after running this command ruby reported the same version on my command line.

Denniss-iMac:~ dennis$ ruby --version
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

So, given that I am getting incompatible library version errors, I will try to delete the ruby/2.3.0 directory as you have suggested. Wish me luck.

Note: Realizing Xcode 10.1 contained the MacOS10.14 SDK, I decided to switch my xcode-select from Xcode 10.1 to 9.4.1 (while still on the same machine with the same OS)… and the problem disappears 🤔 (after the brew audit I had to switch back to Xcode 10.1 to brew install swiftgen though as our formula require Xcode 10…)