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!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)