4

I'm having trouble installing Nokogiri. When I run bundle install or gem install nokogiri the installation fails.

The error I'm getting is: (Note: This failure is from using the installation command on nokogiri.org)

Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    /Users/roneesh/.rbenv/versions/1.9.3-p194/bin/ruby extconf.rb --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28/ --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib
Extracting libxml2-2.8.0.tar.gz into tmp//ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... ERROR, review 'tmp//ports/libxml2/2.8.0/configure.log' to see what happened.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

The command I'm trying to use is:

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28/ --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib

I have installed xml2, xslt and libiconv all with brew, and put in their proper versions above. Still no resolution. The only thing I haven't done is libiconv from source (my wget command isn't working for some reason).

2
  • Why are you passing it all those options?
    – Ryan Bigg
    Jul 28, 2013 at 23:44
  • 1
    Show the contents of tmp//ports/libxml2/2.8.0/configure.log Jul 29, 2013 at 2:11

2 Answers 2

5

You need to specify nokogiri to use the system libraries instead, so it doesn't try to build them itself.

NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install

Answer found here: Error installing nokogiri 1.6.0 on mac (libxml2).

1

Setting NOKOGIRI_USE_SYSTEM_LIBRARIES=1 also did the trick for me, but I had to install the native libraries the gem depends on first (I did it with Homebrew) and then tell the gem to use them.

Summarising:

  • If previously installed, uninstall the gem:
    $ gem uninstall nokogiri

  • Use Homebrew to install libxml2, libxslt and libiconv:
    $ brew install libxml2 libxslt libiconv

  • Install the gem specifying the paths to the libraries to be linked against:
    $ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.