Skip to content

Instantly share code, notes, and snippets.

@kgrz
Created June 20, 2016 05:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kgrz/4ca0223920591cf45979b30a32385532 to your computer and use it in GitHub Desktop.
Save kgrz/4ca0223920591cf45979b30a32385532 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.

Copy link

ghost commented Jun 28, 2016

Thanks, this worked for me

@Xosmond
Copy link

Xosmond commented Jul 2, 2016

Worked for me too. Thanks man.

@jasonknebel
Copy link

Thanks, worked for me too.

@mangiavellano
Copy link

Worked for me, thanks 👍

@pierreem
Copy link

Thanks !

@jasonknebel
Copy link

👍

@troya2
Copy link

troya2 commented Dec 18, 2016

This worked for me after did a brew install libxml2

@sobstel
Copy link

sobstel commented Jan 3, 2017

Alternative install (using xcode libxml2):

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

@wilrnh
Copy link

wilrnh commented Feb 22, 2018

Can also use something like BUNDLE_BUILD__NOKOGIRI="--with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2 --use-system-libraries" bundle update nokogiri

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