Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Possible workaround for installing nokogiri 1.6.8 on OSX with brewed libxml2 2.9.4

Problem:

The following commands fail on OSX:

gem install nokogiri
gem install nokogiri -- --use-system-libraries
gem install nokogiri -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-dir=/usr/local/opt/libxml2

Version:

libxml2: 2.9.4 (installed via homebrew 0.9.9)
libxslt: 1.1.28
nokogiri: 1.6.8

If you tried the last command mentioned above, and the following error message, then this guide might solve your problem:

ERROR: cannot discover where libxml2 is located on your system. please make sure `pkg-config` is installed.

The problem I noticed is that the xmlversion.h header file won't be discovered by extconf.rb script because the inferred path of the include directory by nokogiri is /usr/local/opt/libxml2/include. But in the libxml2 2.9.4 version, the path to the header file is /usr/local/opt/libxml2/include/libxml2/xmlversion.h. Specifying the include and lib paths explicitly solves the problem:

gem install nokogiri -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-include=/usr/local/opt/libxml2/include/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib

I'm not sure if this even a bug, either in functionality or documentation.

@kenjione

This comment has been minimized.

Show comment Hide comment
@kenjione

kenjione Nov 14, 2016

SlatherOrg/slather#227 (comment)

xcode-select --install
gem install nokogiri

Owner

kenjione commented Nov 14, 2016

SlatherOrg/slather#227 (comment)

xcode-select --install
gem install nokogiri

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment