Why is Nokogiri not installing?

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

The error I get: (Note: this error occurs due to using the install 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 installed xml2, xslt and libiconv all with brew and installed their corresponding versions above. Still no permission. The only thing I did not do was libiconv from source (my wget command is not working for some reason).

+4
source share
2 answers

You need to tell nokogiri to use the system libraries, so he does not try to create them himself.

NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install

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

+5
source

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

In summary:

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

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

  • Install a gem that defines the paths to the libraries that you want to link to:
    $ 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"

+1
source

Source: https://habr.com/ru/post/1493983/


All Articles