在Ubuntu / Debian Linux上安装nokogiri

时间:2014-05-14 17:11:15

标签: ruby nokogiri

我正在尝试在Debian Linux上安装nokogiri 1.6.2.1。我正在运行Ruby-2.1.1。我已安装libxml2libxml2-devlibxsltlibxslt-dev

输出:

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.

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

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 */

任何人都可以解释我缺少的东西吗?

2 个答案:

答案 0 :(得分:27)

我需要libgmp-dev:

sudo apt-get install libgmp-dev

关键线在mkmf.log中: /usr/bin/ld: cannot find -lgmp

此行表示找不到libgmp-dev。安装了缺少的lib并重新安装了nokogiri。

答案 1 :(得分:1)

我遇到了同样的问题,并且能够通过apt-get安装问题来回避这个问题。 以下是解决问题的命令:sudo apt-get install ruby-nokogiri