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'
...
You are probably missing zlib headers which are required for
-lz
flag in order to compile the sources correctly. Install on Linux by:For missing libiconv, try installing
libiconv-hook-dev
package which has header files oflibiconv-hook
, e.g.On OS X, try installing development tools via:
xcode-select --install
.If there is still problem, check
mkmf.log
file for more specific details about your error.On Ubuntu, try the following dependency fix combo:
Installing Nokogiri Website
'Installing Nokogiri' is a website dedicated to installing Nokogiri on the major platforms - Here is an excerpt about Installing Nokogiri on Ubuntu:
FYI - I am using Nokogiri 1.6.6.2 and it didn't 'just work'. I got it going with the
--use-system-libraries
.Mac OS X
The website's advice also covers OS X - this worked for me:
gem update --system xcode-select --install gem install nokogiri
Conclusion
If you have a Nokogiri problem on any platform you should check out the website.
On CentOS here is what I needed to do:
The 'could not create Makefile' error you're seeing could also be because you haven't agreed to the Xcode license (you have to agree to it after each time you update Xcode). Running
sudo xcodebuild -license accept
should eliminate this error for you and allow you to then rungem install nokogiri
successfully.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!