root@ubuntu:/home# gem install nokogiri
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb
extconf.rb:5:in
`require': no such file to load -- mkmf (LoadError)
from extconf.rb:5
Gem files will remain installed in
/usr/lib/ruby/gems/1.8/
gems/nokogiri for inspection.
Results logged to
/usr/lib/ruby/gems/1.8/
gems/nokogiri/ext/nokogiri/gem_make.out
I was able to successfully install nokogiri on Windows and Mac so I was confused as to why it is failing in Ubuntu. I found out that you need to install the ruby1.8-dev to make it work.
sudo apt-get install ruby1.8-dev
If that still does not work try to install the following as well:
sudo apt-get install libxml2 libxml2-dev libxslt1-dev
sudo gem install nokogiri
Then just run the gem install nokogiri:
root@ubuntu:/home# gem install nokogiri -v 1.4.3.1
Building native extensions. This could take a while...
Successfully installed nokogiri-1.4.3.1
1 gem installed
Installing ri documentation for nokogiri-1.4.3.1...
r
No definition for parse_memory
No definition for parse_file
No definition for parse_with
No definition for get_options
No definition for set_options
Installing RDoc documentation for nokogiri-1.4.3.1...
No definition for parse_memory
No definition for parse_file
No definition for parse_with
No definition for get_options
This above solution will also work if you get the following error message:
Could not open library 'xml2' : xml2:
cannot open shared object file: No such file or directory.
Could not open library 'libxml2.so' :
libxml2.so: cannot open shared object file: No such file or directory (LoadError)
as mentioned on this blog