skip down to the 13 comments

Installing Nokogiri on CentOS5

Nokogiri is an HTML, XML, SAX, and Reader parser with XPath and CSS selector support. It claims to be a drop in replacement for Hpricot, and it claims to be faster. I think the latter has been addressed but the drop-in bit, well. You see, the Hpricot’s gem had always in the past, just installed, but with Nokogiri I had dependency problems. Turns out I needed a few extra libs that were not installed on my machine. Here’s how I got things going again:

# It seems you need the latest version of rubygems
sudo gem update --system
# and some RPM's
sudo yum install libxml libxml-devel libxslt libxslt-devel
# now the gem should install ok
sudo gem install nokogiri

There have been 13 responses to this post.

  1. Aimee

    Hmm, not working for me at all. I have installed all the XML, XSLT libraries i can think of, plus gems rubyforge, hoe and mocha. What a nuisance.

    Glad to see you have openid, by the way! :)

  2. Duncan

    @Aimee what errors are you getting? and what OS are you installing on?

  3. Aimee

    I am on an Acer Aspire One. It is Linpus Linux which is a variant of Fedora.

    The error is not at all helpful:

    [user@localhost ~]$ sudo gem install nokogiri
    Building native extensions.  This could take a while...
    ERROR:  Error installing nokogiri:
            ERROR: Failed to build gem native extension.
    
    rake RUBYARCHDIR=/usr/local/lib/ruby/gems/1.8/gems/nokogiri-1.0.6/lib \
    RUBYLIBDIR=/usr/local/lib/ruby/gems/1.8/gems/nokogiri-1.0.6/lib
    sh: rake: command not found
    
    
    Gem files will remain installed in /usr/local/lib/ruby/gems/1.8/gems/nokogiri-1.0.6 for inspection.
    Results logged to /usr/local/lib/ruby/gems/1.8/gems/nokogiri-1.0.6/gem_make.out
  4. Duncan

    Looks like you need rake installed for starters.

    sudo gem install rake
  5. Aimee

    No, i have rake. It’s a really unhelpful message, isn’t it?! I guess it just means that rake caused the problem, but i still don’t really know what the problem was.

  6. Duncan

    The error would indicate that it can not find your rake command even if it is installed. What do these commands return:

    which rake
    echo $PATH
    

    return?

  7. Aimee

    You won’t believe this:

    [user@localhost ~]$ which rake
    /usr/local/bin/rake
    [user@localhost ~]$ echo $PATH
    /usr/kerberos/bin:/usr/local/MobilePartner/java/jre1.5.0_15/bin/: \
    /usr/local/bin:/bin:/usr/bin:/usr/acer/bin:/sbin/:/usr/sbin/: \
    /home/user/bin:/usr/acer/bin:/sbin/:/usr/sbin/:/home/user/bin:/usr/acer/bin
    [user@localhost ~]$ rake --version
    rake, version 0.8.3

    Umm, any other possible explanations?!

    I really do appreciate your help, by the way. I am completely stumped!

  8. Duncan

    Sorry Aimee, I’m running out of ideas. Could you post the content of:

    /usr/local/lib/ruby/gems/1.8/gems/nokogiri-1.0.6/gem_make.out

    just to see if it holds any secrets.

  9. Aimee

    Hey, you know what, i’ve no idea what the problem was, but Aaron (tenderlove) has given me an alternative.

    I’ve installed a dev version of the next release, which does not use Rake to install. Now i have webrat and cucumber and it all works a treat!

    Thank you so much for your help. We maybe will remain forever baffled by the original problem.

  10. Duncan

    That’s great news! We’re also using Cucumber here on an upcoming project. One of my colleagues started the ball rolling http://bit.ly/pxdA

  11. deshi

    gem install nokogiri — –with-xml2-lib=/usr/lib –with-xml2-include=/usr/include/libxml2 \
    –with-xslt-lib=/usr/lib –with-xslt-include=/usr/include/libxslt/

  12. loganathan

    XSD validation fails in centos 5.4 :(

  13. Juan Fernandez

    Thank you!

    After following your instructions, nokogiri installed.


back to the top