【问题标题】:How to install Nokogiri with Rails on Ubuntu 16.04如何在 Ubuntu 16.04 上使用 Rails 安装 Nokogiri
【发布时间】:2019-06-13 16:50:37
【问题描述】:

我正在尝试使用

安装 Rails
sudo gem install rails

在新版本的 Ubuntu 16.04 上。 Ruby 2.3.1p112 已经安装。在安装 Rails 期间,一旦获取 Nokogiri 完成,我收到以下错误:

Fetching: nokogiri-1.8.0.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
        ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/nokogiri-1.8.0/ext/nokogiri
/usr/bin/ruby2.3 -r ./siteconf20170608-1635-1vnwqbn.rb extconf.rb
checking if the C compiler accepts ... *** 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/bin/$(RUBY_BASE_NAME)2.3
        --help
        --clean
/usr/lib/ruby/2.3.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/lib/ruby/2.3.0/mkmf.rb:571:in `block in try_compile'
        from /usr/lib/ruby/2.3.0/mkmf.rb:522:in `with_werror'
        from /usr/lib/ruby/2.3.0/mkmf.rb:571:in `try_compile'
        from extconf.rb:138:in `nokogiri_try_compile'
        from extconf.rb:162:in `block in add_cflags'
        from /usr/lib/ruby/2.3.0/mkmf.rb:629:in `with_cflags'
        from extconf.rb:161:in `add_cflags'
        from extconf.rb:407:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/nokogiri-1.8.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/nokogiri-1.8.0 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/nokogiri-1.8.0/gem_make.out

这是mkmf.log的内容:

"gcc -o conftest -I/usr/include/x86_64-linux-gnu/ruby-2.3.0 -I/usr/include/ruby-2.3.0/ruby/backward -I/usr/include/ruby-2.3.0 -I. -Wdate-time -D_FORTIFY_SOURCE=2   -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC  conftest.c  -L. -L/usr/lib/x86_64-linux-gnu -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic     -lruby-2.3  -lpthread -lgmp -ldl -lcrypt -lm   -lc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

我不知道出了什么问题。日志没有帮助,我已经尝试安装 libgmp-devruby-devzlib1g-devliblzma-dev,因为它们被建议给在 Nokogiri gem 安装期间遇到错误的人。

【问题讨论】:

  • 任何在 Linux 上使用 RVM 并在尝试安装 Rails 时遇到问题的人,另请参阅 stackoverflow.com/q/29317640/128421
  • 我也遇到过同样的问题。找不到解决办法。

标签: ruby ubuntu nokogiri ruby-on-rails-5


【解决方案1】:

在尝试查找丢失的依赖项一段时间后,我在 mkmf.log 中运行了gcc 命令,以防某些编译错误消息被忽略。

原来我没有安装 gcc。安装后,我在安装方面取得了一些进展,但遇到了另一个类似的错误。最后,安装下面的依赖项导致 Rails 安装成功。

在运行gem install rails之前,请确保您已安装gcc, make, zlib1g-dev, sqlite3

sudo apt-get install gcc make zlib1g-dev sqlite3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-24
    • 2016-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多