【问题标题】:Bundle install error installing nokogiri (1.6.7.2). Gem installs but not for rails app捆绑安装错误安装 nokogiri (1.6.7.2)。 Gem 安装但不适用于 rails 应用程序
【发布时间】:2019-06-17 05:03:36
【问题描述】:

我正在开发一个使用 ruby​​ 2.1.5 的 Rails 项目。我下载了 rvm,安装了 ruby​​ 2.1.5,目前正在使用它。我在 Ubuntu 18.04 上。我在运行bundle install 时收到以下错误

当我按照指示尝试gem install nokogiri -v '1.6.7.2' 时,它安装得很好。在这种情况下,我找不到另一个问题。

我查看了这个问题Error while installing Nokogiri (1.6.7) on El Capitan 并尝试了所有解决方案。这可能是我遇到的另一个问题。它可能与rvm有关,但我不确定。

$ bundle install
Fetching gem metadata from https://rubygems.org/........
Using rake 11.1.2
Using CFPropertyList 2.3.3
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.4
Using thread_safe 0.3.5
Using tzinfo 1.2.2
Using activesupport 4.2.4
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.0.0
Fetching nokogiri 1.6.7.2
Installing nokogiri 1.6.7.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/media/mcgoy/CD25-ED8E/Upwork/EVSlideShow/Rails/vendor/bundle/ruby/2.1.0/gems/nokogiri-1.6.7.2/ext/nokogiri
/usr/share/rvm/rubies/ruby-2.1.5/bin/ruby -r ./siteconf20190123-15188-1qpzj0b.rb extconf.rb
--use-system-libraries
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/share/rvm/rubies/ruby-2.1.5/bin/ruby
    --help
    --clean
/usr/share/rvm/rubies/ruby-2.1.5/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 /usr/share/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/mkmf.rb:571:in `block in try_compile'
    from /usr/share/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/mkmf.rb:522:in `with_werror'
    from /usr/share/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/mkmf.rb:571:in `try_compile'
    from extconf.rb:80:in `nokogiri_try_compile'
    from extconf.rb:87:in `block in add_cflags'
    from /usr/share/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/mkmf.rb:621:in `with_cflags'
    from extconf.rb:86:in `add_cflags'
    from extconf.rb:336:in `<main>'

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

/media/mcgoy/CD25-ED8E/Upwork/EVSlideShow/Rails/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0/nokogiri-1.6.7.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/media/mcgoy/CD25-ED8E/Upwork/EVSlideShow/Rails/vendor/bundle/ruby/2.1.0/gems/nokogiri-1.6.7.2
for inspection.
Results logged to
/media/mcgoy/CD25-ED8E/Upwork/EVSlideShow/Rails/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0/nokogiri-1.6.7.2/gem_make.out

An error occurred while installing nokogiri (1.6.7.2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.7.2' --source 'https://rubygems.org/'` succeeds
before bundling.

In Gemfile:
  rails was resolved to 4.2.4, which depends on
    actionmailer was resolved to 4.2.4, which depends on
      actionpack was resolved to 4.2.4, which depends on
        actionview was resolved to 4.2.4, which depends on
          rails-dom-testing was resolved to 1.0.7, which depends on
            nokogiri

但是如你所见,当我运行gem install nokogiri -v '1.6.7.2' 时,看起来没有问题

$ gem install nokogiri -v 1.6.7.2
Building native extensions. This could take a while...
Successfully installed nokogiri-1.6.7.2
Parsing documentation for nokogiri-1.6.7.2
Done installing documentation for nokogiri after 2 seconds
1 gem installed

【问题讨论】:

    标签: ruby-on-rails rvm


    【解决方案1】:

    这里参考Installing Nokogiri

    gem update --system
    xcode-select --install # Then agree to the terms, even if you have done this before!
    gem install nokogiri
    
    # if that's still not working uninstall the old nokogiri 
    gem uninstall nokogiri
    

    上面对于 mac os 和 ubuntu 的选项已经由 javier 提到(在其他答案中,如果问题仍然存在,我的建议你先执行 gem uninstall nokogiri 然后执行 gem install nokogiri -v '1.6.7.2'

    【讨论】:

    • 这些说明适用于 OSX,我可以将其用于 Ubuntu 吗?什么是 xcode-select?
    • xcode-select 仅适用于 mac os ,它是包库(在执行 sudo apt-get install 时与 ubuntu 几乎相同),我的建议是先卸载,然后使用 gem install nokogiri -v '1.6 安装。 7.2'
    【解决方案2】:

    这些是 ubuntu docs 的说明

    sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev
    

    对于 rvm

    sudo apt-get install libgmp-dev
    

    使用系统库构建

    sudo apt-get install libxml2-dev libxslt1-dev
    

    安装

    gem install nokogiri --use-system-libraries
    

    【讨论】:

    • 谢谢。已安装。但同样的问题仍然存在!
    • 试试这个:gem install nokogiri -v '1.6.7.2' --use-system-libraries,这应该会引发错误
    • @RandallCoding 我认为问题在于捆绑安装正在使用此选项--use-system-libraries,并且您的系统可能缺少 libxml2-dev 和 libxslt1-dev
    【解决方案3】:

    我修复了它,但它可能是一个不令人满意的答案。我浏览了所有建议,安装了各种依赖项,更改了各种设置。似乎没有任何效果。 然后我删除了项目文件夹,从 Github 再次拉取,重新安装了 rvm,再次运行bundle install,一切正常。

    那么我错过的一件事是什么?我不能确定。但我可以说如果没有其他工作,创建一个新文件夹并再次下载项目并运行bundle install.. 当然首先安装所有依赖项/工具后,在这里找到 -> https://nokogiri.org/tutorials/installing_nokogiri.html

    【讨论】:

      猜你喜欢
      • 2015-05-15
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-08
      相关资源
      最近更新 更多