新手问题 升级到 Rails 5 时 gem nio4r 无法安装问题

somejump · 2017年02月06日 · 最后由 somejump 回复于 2017年02月06日 · 3353 次阅读

本小白在笔记本上写 ROR 程序时,这个 gem 成功安装了。现在在服务器上反而装不上了...... 服务器原本是 ruby 2.0.0,后来因为 rails5 要求必须升到 2.2.2 于是就出现了下面这个 bug 下面是运行命令时的错误记录:

root@hostname:/home/times# gem install nio4r -v '1.2.1'
Building native extensions.  This could take a while...
ERROR:  Error installing nio4r:
    ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-2.2.2/bin/ruby -r ./siteconf20170206-7959-12h81e9.rb extconf.rb
checking for unistd.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.

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=/usr/local/rvm/rubies/ruby-2.2.2/bin/$(RUBY_BASE_NAME)
/usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:587:in `try_cpp'
    from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:1060:in `block in have_header'
    from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:911:in `block in checking_for'
    from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:351:in `block (2 levels) in postpone'
    from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:321:in `open'
    from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:351:in `block in postpone'
    from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:321:in `open'
    from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:347:in `postpone'
    from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:910:in `checking_for'
    from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:1059:in `have_header'
    from extconf.rb:3:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.2.2/gems/nio4r-1.2.1 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.2.2/extensions/x86_64-linux/2.2.0/nio4r-1.2.1/gem_make.out

其中这一句话我觉得比较重要: 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. 以及我尝试顺藤摸瓜找到的详细错误信息(位置:/usr/local/rvm/gems/ruby-2.2.2/extensions/x86_64-linux/2.2.0/nio4r-1.2.1/mkmf.log)

"gcc -o conftest -I/usr/local/rvm/rubies/ruby-2.2.2/include/ruby-2.2.0/x86_64-linux -I/usr/local/rvm/rubies/ruby-2.2.2/include/ruby-2.2.0/ruby/backward -I/usr/local/rvm/rubies/ruby-2.2.2/include/ruby-2.2.0 -I.     -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 -Wdeprecated-declarations -Wno-packed-bitfield-compat  -fPIC conftest.c  -L. -L/usr/local/rvm/rubies/ruby-2.2.2/lib -Wl,-R/usr/local/rvm/rubies/ruby-2.2.2/lib -L. -fstack-protector -rdynamic -Wl,-export-dynamic     -Wl,-rpath,'/../lib' -Wl,-R'/../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 */

我的想法是应该是缺了某些包,但是详细报错看不懂,也没有讲缺什么包,求大神解救~

You have to install development tools first.

sudo apt-get install libgmp3-dev

issue

Maybe help.

#1 楼 @flowerwrong Thank you very much! It did work! I can't even find solution on stackoverflow.😉

somejump 关闭了讨论。 02月06日 09:36
需要 登录 后方可回复, 如果你还没有账号请 注册新账号