Installing nokogiri on Ubuntu/Debian Linux
Asked Answered
E

2

9

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?

Economically answered 14/5, 2014 at 17:11 Comment(4)
This question appears to be off-topic because it is about operating system package dependencies.Resiniferous
Maybe I should not have taged with the ruby tag? I put it in becuse I could not get nokogiri to install. Is that considered off topic?Economically
It is installation of a programming package. It belongs on StackOverflow, and is not off-topicWick
Can someone explain to me why this is off topic? There are others questions that have not been marked as off topic and are related: link and link.Economically
E
27

I needed libgmp-dev:

sudo apt-get install libgmp-dev

The key line was in the mkmf.log: /usr/bin/ld: cannot find -lgmp

This line indicates that libgmp-dev could not be found. Installed the missing lib and reinstalled nokogiri.

Economically answered 14/5, 2014 at 17:11 Comment(0)
G
2

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

Geminian answered 9/11, 2017 at 21:3 Comment(1)
this is actually the correct answer for debian users who cant get to install nokogiri using gem install nokogiriMunda

© 2022 - 2024 — McMap. All rights reserved.