Building Nokogiri on El Capitan

Last week I couldn’t generate one of my websites with Jekyll. After some research I noticed that it was complaining about Nokogiri. I had the problem before, but I didn’t document it well enough so I had to troubleshoot the whole process again.
It seems that everytime I have an update, security or not, compiling of Nokogiri goes wrong.

I had all sorts of error messages:

  • ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension.
  • Failed to build gem native extension. libxml2 version 2.6.21 or later is required!

and more I unfortunately didn’t write down.

Although the Nokogiri website had a good installation guide, it still didn’t work on my Mac.

After a lot of searching on the internet I found my solution: Compiling it to the libraries from brew.

First install the libraries with

brew install libxml2 libxslt

and then compile it with:

NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir=/usr/lib --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xml2-include="$(brew --prefix libxml2)/include/libxml2" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"

If you are using bundle to run Jekyll you have to configure the build settings for Nokogiri with:

bundle config build.nokogiri --use-system-libraries --with-iconv-dir=/usr/lib --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xml2-include="$(brew --prefix libxml2)/include/libxml2" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"

bundle install

That did the trick for me. Now bundle installs Nokogiri without errors.

Leave a Reply

Previous post Check the readability of a post before posting
Next post Removing ghost e-mails from Smart Mailboxes