Skip to content

Instantly share code, notes, and snippets.

@kenjione
Forked from kgrz/workaround.md
Created July 5, 2016 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenjione/354a229dcd63ab020bcefc6a98616372 to your computer and use it in GitHub Desktop.
Save kenjione/354a229dcd63ab020bcefc6a98616372 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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