I’m installing the Ruby Nokogiri gem and finding the error below.
How to diagnose this and solve it?
# gem install nokogiri
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
...
/opt/ruby/1.9.3-p194/bin/ruby extconf.rb
checking for libxml/parser.h... *** 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.
...
/opt/ruby/1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do':
The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /opt/ruby/1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
...
To diagnose and solve, here’s what worked for me.
To find out what failed, go to your ruby gems directory.
For example:
If you don’t know your gem directory, try this:
What version of nokogiri am I installing?
Go to the installer directory:
Try installing manually:
Result:
I’m using Ubuntu so I search for any similar packages:
Results:
I believe that libxml2 will work fine.
Ruby native gems often need the *-dev packages for headers so install them:
Now do I have the parser file?
Yes, the result shows the parser:
Now try installing again, this time providing the libxml2 path:
It still fails, so read the mkmf error log:
The error log shows what failed and has these lines that look promising:
Is there a package for it?
Results:
Install the dev package:
Now try installing again, and also put xslt on the path:
Success!