How to Install Nokogiri Ruby Gem with Mkmf.Log Saying Libiconv Not Found

How to install Nokogiri Ruby gem with mkmf.log saying libiconv not found?

To diagnose and solve, here's what worked for me.

To find out what failed, go to your ruby gems directory.

For example:

$ cd <MY RUBY DIRECTORY>/lib/ruby/gems/2.0.0/gems

If you don't know your gem directory, try this:

$ echo $GEM_HOME
/opt/gems/2.0.0
$ cd /opt/gems/2.0.0/gems

What version of nokogiri am I installing?

$ ls -ladg nokogiri-*
nokogiri-1.5.5

Go to the installer directory:

$ cd nokogiri-1.5.5/ext/nokogiri

Try installing manually:

$ ruby extconf.rb

Result:

checking for libxml/parser.h... *** extconf.rb failed ***
...

I'm using Ubuntu so I search for any similar packages:

$ aptitude search libxml

Results:

p libxml2 - GNOME XML library
p libxml2-dev - Development files for the GNOME XML library
...

I believe that libxml2 will work fine.

$ apt-get install libxml2

Ruby native gems often need the *-dev packages for headers so install them:

$ apt-get install libxml2-dev

Now do I have the parser file?

$ find / | grep libxml/parser.h

Yes, the result shows the parser:

/usr/include/libxml2/libxml/parser.h

Now try installing again, this time providing the libxml2 path:

$ gem install nokogiri -- --with-xml2-dir=/usr/include/libxml2

It still fails, so read the mkmf error log:

$ more mkmf.log 

The error log shows what failed and has these lines that look promising:

package configuration for libxslt is not found

Is there a package for it?

$ aptitude search libxslt

Results:

v   libxslt-dev
i libxslt-ruby
...

Install the dev package:

$ apt-get install libxslt-dev

Now try installing again, and also put xslt on the path:

$ gem install nokogiri -- \
--with-xml2-dir=/usr/include/libxml2 \
--with-xslt-dir=/usr/include/libxslt

Success!

Why does installing Nokogiri on Mac OS fail with libiconv is missing?

I had the same issue. Unfortunately the "Installing Nokogiri" doesn't cover Iconv issues. Here's how I resolved the issue.

First install homebrew, it'll make your life easier. If you already have it installed, be sure to grab the latest formulae by updating like so:

brew update

Note: In OSX 10.9+ you may need to install xCode command tools to allow you to install libiconv.

xcode-select --install

then install a newer version of libiconv

brew install libiconv

then install your gem

gem install nokogiri -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14

Error FOR gem install nokogiri AND bundle install FOR Middleman app

This command:

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

found in this github issue, solved my problem. Honestly, I'm not entirely sure why so if anyone could append a comment, elucidating what exactly is going on it would be much appreciated.

nokogiri gem installation error

Finally, the problem was caused by nokogiri itself by shipping it's own libxml2 that's incompatible with some systems.

So to install nokogiri I had to tell it that it should use the system libraries.

I installed it manually by:

gem install nokogiri -v 1.6.2.1 -- --use-system-libraries

And it worked well. Other answers didn't solve it.

Failing to install Nokogiri gem

This works like a charm!

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

https://stackoverflow.com/a/24511149

Failed to gem install nokogiri in Fedora16

Finally got it work, here are the steps:

  • Download libiconv

    wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.11.tar.gz

  • Extract files tar -xvzf libiconv-1.11.tar.gz

  • Enter the directory cd libiconv-1.11

  • Configure libiconv Library ./configure --prefix=/usr/local/libiconv

  • Compile libiconv make CFLAGS="-O2 -fno-tree-dce -fno-optimize-sibling-calls" (I have to add CFLAGS to make the compiling work.)

  • Install libiconv sudo make install

  • Install nokogiri
    CFLAGS="-O2 -fno-tree-dce -fno-optimize-sibling-calls" gem install nokogiri -- --with-iconv-dir=/usr/local/libiconv --with-iconv-lib=/usr/local/libiconv/lib --with-iconv-include=/usr/local/libiconv/include

Voila, it shows the success message!

Failure to install nokogiri libiconv is missing on Yosemite Mac OS X 10.10

The nokogiri install tutorial provides the solution:

# bash
brew unlink gcc
gem uninstall nokogiri
xcode-select --install
gem install nokogiri

If you don't have Xcode 6.1, yet, you may install it from the apple developer download site (section additional tools), as described in this blog post.

An error occurred while installing nokogiri (1.6.0), and Bundler cannot continue

I delete the Gemfile.lock, then run bundle install. Everything is ok! :)



Related Topics



Leave a reply



Submit