16

I tried to install Nokogiri but I always get an compiling error:

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

but, I've installed it and all other dependencies.

I try to give the installer hints like this:

%> gem install nokogiri -- --with-xml2-lib=/usr/lib/ --with-xml2-include=/usr/include/libxml2/

...

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

...

but it still doesn't install:

%> find /usr/include/ -name "parser.h"    
/usr/include/libxml2/libxml/parser.h
...

I'm on Ubuntu 11.10.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Output of:

"dpkg-query -l | grep xml" and "dpkg-query -l | grep xslt"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The failure seem to be on the side of GCC:

%> cat hello.c
#include <stdio.h>

main()
{
   printf("Hello World \n");
}

%> gcc hello.c
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x12): undefined reference to `__libc_csu_fini'
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x19): undefined reference to `__libc_csu_init'
collect2: ld gab 1 als Ende-Status zurück
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Manuel Görlich
  • 169
  • 1
  • 4
  • 1
    It would be helpful to know what operating system this is. – Ryan Bigg Mar 06 '12 at 18:57
  • Trying a different approach - you should have an `mkmf.log` file from the directory where the install failed. Can you show us the contents of that file? Also - do you have the build tools and compilers installed on your system? `extconf.rb` might be attempting to do test building. Try to run something like `gcc` or `make` from the command line, see if they respond. – wkl Mar 06 '12 at 21:33
  • 4
    I think you truly don't have them installed. Did you install them using `sudo apt-get install libxml2-dev libxslt-dev`? – Ryan Bigg Mar 07 '12 at 00:58
  • 1
    Hmm, I ran into similar issue on Mac OSX today for nokogiri 1.5.2 – Phương Nguyễn May 17 '12 at 16:25
  • Looks like the libraries are not correct for the architecture. Could you run: 1. `which gcc`, 2.`dpkg-query -S "crt1.o"|grep "/crt1.o"`. Are you on x64? – Jarekczek Sep 21 '12 at 18:40
  • 1
    This question should be re-opened. I had this issue using ubuntu 13.04 on an Amazon ec2 instance. I think a large number of people could be helped by this question as I was. – wuliwong Aug 18 '13 at 22:28

2 Answers2

22

This will work.

sudo apt-get install libxslt-dev libxml2-dev
gem install nokogiri
earlonrails
  • 4,966
  • 3
  • 32
  • 47
  • 1
    might have to uninstall nokogirl and/or libxml-ruby first ala: gem uninstall nokogiri; gem uninstall libxml-ruby; then reinstall – Erik Petersen Oct 05 '12 at 23:22
  • I keep getting this error and having to use this solution everytime I try to run a Rails 3 app. – Donato May 23 '15 at 20:32
2

I just faced the same issue on (cat /etc/centos-release:) CentOS release 6.6 (Final).

sudo yum install -y rubygem-nokogiri

…fixed that problem.

(see: http://www.nokogiri.org/tutorials/installing_nokogiri.html#red_hat___centos)

klaus
  • 1,806
  • 17
  • 20
  • I got away with `yum install libxml2-devel libxslt-devel` (on CentOS 6.7). I don't have the system Ruby installed, so this saves me having to install a bunch of Ruby-related dependencies. – mwfearnley Dec 05 '17 at 09:27