安装nokogiri(1.6.7.2)时出现捆绑安装错误。宝石安装但不适用于Rails应用

时间:2019-01-23 15:00:31

标签: ruby-on-rails rvm

我正在研究使用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

3 个答案:

答案 0 :(得分: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

上面针对macos和ubuntu的选项已经被javier提及(换句话说,如果问题仍然存在,我的建议是先卸载gem nokogiri,然后再安装nokogiri -v'1.6.7.2'

答案 1 :(得分:1)

这些是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

答案 2 :(得分:0)

我已修复它,但这可能是一个不令人满意的答案。我仔细阅读了所有建议,安装了各种依赖项,更改了各种设置。似乎没有任何工作。 然后,我删除了项目文件夹,并将其从Github中再次拉出,重新安装了rvm,再次运行m <- matrix(c(0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 2, 1, 1, 2, 0), nrow = 4, ncol = 4) rownames(m) <- letters[1:4]; colnames(m) <- letters[1:4] > m a b c d a 0 1 1 1 b 1 0 0 1 c 1 0 0 2 d 1 1 2 0 ,一切都正常工作。

那我缺少的一件事是什么?我不能确定但是我可以说,如果其他方法无效,请创建一个新文件夹,然后再次下载该项目,然后运行bundle install ..当然首先要在安装所有依赖项/工具之后,在此处找到-> https://nokogiri.org/tutorials/installing_nokogiri.html