15

I am trying to setup rails env on my new ubuntu machine. But I am facing trouble while install nokogiri gem.. I have installed libxslt and libxml2 libs thourgh rvm pkg command as well as using apt-get. I thought it is showing me libxslt is missing error.

Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

        /home/hacker5/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb --with-xslt-include=/usr/include/libxslt
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... yes
checking for xmlParseDoc() in -lxml2... yes
checking for xsltParseStylesheetDoc() in -lxslt... no
-----
libxslt is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----

EDIT

I am using rvm setup and ruby 1.9.3

Hardik Joshi
  • 839
  • 2
  • 8
  • 14
  • possible duplicate of [error installing nokogiri 1.5.0 with rails 3.1.0 and ubuntu](http://stackoverflow.com/questions/8003523/error-installing-nokogiri-1-5-0-with-rails-3-1-0-and-ubuntu) – Rubyrider Dec 24 '14 at 07:56

8 Answers8

24

Try this:

# nokogiri requirements
sudo apt-get install libxslt-dev libxml2-dev
gem install nokogiri
Hertzel Guinness
  • 5,912
  • 3
  • 38
  • 43
Benjamin Tan Wei Hao
  • 9,621
  • 3
  • 30
  • 56
10

For Ruby 1.9.3 and 2.0, libxslt-dev and libxml2-dev are required.

sudo apt-get install libxslt-dev libxml2-dev

rdsoze
  • 1,768
  • 1
  • 15
  • 25
  • Yes , this ran like a champ. You run this if you already have RUBY installed . and it worked. – z atef Jun 04 '14 at 01:55
9

this is what worked for me:

  1. install nokogiri's dependencies

    sudo apt-get install libxslt-dev libxml2-dev

  2. make sure nokogiri uses the system libraries

    export NOKOGIRI_USE_SYSTEM_LIBRARIES=1

  3. install nokogiri with the --verbose option, to get a better understanding of any problems

    gem install --verbose nokogiri

kitteehh
  • 442
  • 7
  • 10
  • `gem install --verbose nokogiri` was exactly what I needed. Error: "virtual memory exhausted: Cannot allocate memory" - _sigh_ – Peter Klipfel Apr 28 '16 at 22:25
6

Since I stumbled upon this, here's what I did to resolve:

sudo apt-get install ruby1.9.1-dev
ntwrkguru
  • 1,644
  • 1
  • 11
  • 14
5

On 14.0.4, using RVM, you need:

sudo apt-get install -y libgmp-dev
blnc
  • 4,384
  • 1
  • 28
  • 42
Hiccup
  • 51
  • 1
  • 1
  • *This is the solution to the latest error* **Ubuntu** `14.04.4 LTS` **Ruby** `2.3.0` – blnc Apr 01 '16 at 20:52
2

Install ruby via rvm and then install below libs:

sudo apt-get install libxslt-dev libxml2-dev

now try to install gem without sudo:

gem install nokogiri
tokhi
  • 21,044
  • 23
  • 95
  • 105
2

apt-get install libxslt-dev libxml2-dev -y && export NOKOGIRI_USE_SYSTEM_LIBRARIES=1 && gem install --verbose nokogiri

Dan
  • 21
  • 2
1

for Centos / Redhat, try this: sudo yum install libxslt-devel libxml2-devel

worldask
  • 1,837
  • 3
  • 22
  • 37