Installing Nokogiri from a Gemfile on Mojave

November 13, 2018

Another MacOS and another struggle through installing nokogiri. Most places online recommend using --with-xml2-include and --use-system-libraries during gem install, but if you're installing from a Gemfile using bundle install, it can sometimes be a little trickier.

To enable passing args like this to a gem installed from a Gemfile, we can use Bundler Config. The magic command to run before bundle install on Mojave is:

bundle config build.nokogiri --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2   --use-system-libraries