Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing nokogiri on Ubuntu/Debian Linux

Tags:

ruby

nokogiri

I am trying to install nokogiri 1.6.2.1 on Debian Linux. I am running Ruby-2.1.1. I have installed libxml2, libxml2-dev, libxslt, and libxslt-dev.

Output:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.<br>
    /home/xxx/.rvm/rubies/ruby-2.1.1/bin/ruby extconf.rb 
Building nokogiri using packaged libraries.
checking for iconv.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.<br>
Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/home/xxx/.rvm/rubies/ruby-2.1.1/bin/ruby
    --help
    --clean
    --use-system-libraries
    --enable-static
    --disable-static
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --enable-cross-build
    --disable-cross-build
/home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:587:in `try_cpp'
    from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:1067:in `block in have_header'
    from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:918:in `block in checking_for'
    from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:351:in `block (2 levels) in postpone'
    from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:321:in `open'
    from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:351:in `block in postpone'
    from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:321:in `open'
    from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:347:in `postpone'
    from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:917:in `checking_for'
    from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:1066:in `have_header'
    from extconf.rb:103:in `have_iconv?'
    from extconf.rb:148:in `block (2 levels) in iconv_prefix'
    from extconf.rb:90:in `preserving_globals'
    from extconf.rb:143:in `block in iconv_prefix'
    from extconf.rb:120:in `each_iconv_idir'
    from extconf.rb:137:in `iconv_prefix'
    from extconf.rb:424:in `block in <main>'
    from extconf.rb:161:in `block in process_recipe'
    from extconf.rb:154:in `tap'
    from extconf.rb:154:in `process_recipe'
    from extconf.rb:419:in `<main>'<br>
extconf failed, exit code 1<br>
Gem files will remain installed in /home/xxx/.rvm/gems/ruby-2.1.1/gems/nokogiri-1.6.2.1 for inspection.
Results logged to /home/xxx/.rvm/gems/ruby-2.1.1/extensions/x86-linux/2.1.0/nokogiri-1.6.2.1/gem_make.out
An error occurred while installing nokogiri (1.6.2.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.2.1'` succeeds before bundling.

Contents from the gem_make.out:

/home/xxx/.rvm/rubies/ruby-2.1.1/bin/ruby extconf.rb 
Building nokogiri using packaged libraries.
checking for iconv.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.<br>
Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/xxx/.rvm/rubies/ruby-2.1.1/bin/ruby
        --help
        --clean
        --use-system-libraries
        --enable-static
        --disable-static
        --with-zlib-dir
        --without-zlib-dir
        --with-zlib-include
        --without-zlib-include=${zlib-dir}/include
        --with-zlib-lib
        --without-zlib-lib=${zlib-dir}/lib
        --enable-cross-build
        --disable-cross-build
/home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:587:in `try_cpp'
        from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:1067:in `block in have_header'
        from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:918:in `block in checking_for'
        from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:351:in `block (2 levels) in postpone'
        from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:321:in `open'
        from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:351:in `block in postpone'
        from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:321:in `open'
        from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:347:in `postpone'
        from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:917:in `checking_for'
        from /home/xxx/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/mkmf.rb:1066:in `have_header'
        from extconf.rb:103:in `have_iconv?'
        from extconf.rb:148:in `block (2 levels) in iconv_prefix'
        from extconf.rb:90:in `preserving_globals'
        from extconf.rb:143:in `block in iconv_prefix'
        from extconf.rb:120:in `each_iconv_idir'
        from extconf.rb:137:in `iconv_prefix'
        from extconf.rb:424:in `block in <main>'
        from extconf.rb:161:in `block in process_recipe'
        from extconf.rb:154:in `tap'
        from extconf.rb:154:in `process_recipe'
        from extconf.rb:419:in `<main>'<br>
extconf failed, exit code 1

Contents from the mkmf.log:

"gcc -o conftest -I/home/xxx/.rvm/rubies/ruby-2.1.1/include/ruby-2.1.0/i686-linux -I/home/xxx/.rvm/rubies/ruby-2.1.1/include/ruby-2.1.0/ruby/backward -I/home/xxx/.rvm/rubies/ruby-2.1.1/include/ruby-2.1.0 -I. -I/usr/include  -D_FILE_OFFSET_BITS=64   -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fPIC  -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline conftest.c  -L. -L/home/xxx/.rvm/rubies/ruby-2.1.1/lib -Wl,-R/home/xxx/.rvm/rubies/ruby-2.1.1/lib -L/usr/lib -Wl,-R/usr/lib -L. -fstack-protector -rdynamic -Wl,-export-dynamic     -Wl,-R -Wl,/home/xxx/.rvm/rubies/ruby-2.1.1/lib -L/home/xxx/.rvm/rubies/ruby-2.1.1/lib -lruby  -lpthread -lgmp -ldl -lcrypt -lm   -lc "
/usr/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

Can anyone explain what I am missing?

like image 956
rjenkins Avatar asked May 14 '14 17:05

rjenkins


People also ask

Can t install Nokogiri?

Solution. Uninstall all versions of Nokogiri on your system, and then re-resolve your dependencies (using bundle or gem install ). This error can occur when a version of Nokogiri installed for a different version of Ruby is used by an unsupported version of Ruby. For example, if Nokogiri v1.

Is Nokogiri a ruby gem?

One of the best gems for Ruby on Rails is Nokogiri which is a library to deal with XML and HTML documents. The most common use for a parser like Nokogiri is to extract data from structured documents.

What is GEM Nokogiri?

The Nokogiri gem is an incredible open-source tool that parses HTML and XML data. It is one of the most widely used gems available, and it can really take your Ruby app to another level for data with its ability to help you intuitively scrape websites.

What is Nokogiri used for?

Nokogiri (htpp://nokogiri.org/) is the most popular open source Ruby gem for HTML and XML parsing. It parses HTML and XML documents into node sets and allows for searching with CSS3 and XPath selectors. It may also be used to construct new HTML and XML objects.


1 Answers

I was having the same problem and was able to sidestep the issue by installing it via apt-get. Here is the command that solved the issue: sudo apt-get install ruby-nokogiri

like image 149
andrewkiri Avatar answered Oct 14 '22 21:10

andrewkiri