After upgrading to macOS Mojave gem update is failing

The error is due to macOS Mojave has stopped placing the standard header files in /usr/include, keeping them only inside the XCode directory.

You can verify this by running ls /usr/include and most likely this directory does not exist anymore. On contrary, the usual trick by running xcode-select --install will not solve the problem.

The fix is to run legacy installer provided by Apple that will install the header files to /usr/include

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /


Also, you may have outdated bundle config, which is in the way. Run bundle config build.nokogiri --use-system-libraries and it'll give you a warning and show what config you currently have. I was following all guides and reinstalled all gems and even ruby a few times only to find out that config was set to use a path that doesn't exist anymore.


If you are using homebrew, the recommended approach is to tell pkg-config where it can find the libxml2 library:

brew reinstall libxml2
export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig"

Tags:

Macos

Rubygems