Ruby-on-rails 运行 bundle install 时出现 Nokogiri 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17204152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:11:38  来源:igfitidea点击:

Nokogiri error when running bundle install

ruby-on-railsrubyrubygemsnokogirirbenv

提问by wikichen

Trying to get a cloned Rails app running. When running bundle installI get this error:

试图让克隆的 Rails 应用程序运行。运行时出现bundle install此错误:

Using mini_portile (0.5.0)
Installing nokogiri (1.6.0)
Gem::InstallError: nokogiri requires Ruby version >= 1.9.2.
An error occurred while installing nokogiri (1.6.0), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.0'` succeeds before bundling.

But this is the output for rbenv version:

但这是输出rbenv version

? rbenv version
1.9.3-p429 (set by /Users/andrewguo/.rbenv/version)

When running gem listI get:

运行时gem list我得到:

.
.
.
mini_portile (0.5.0)
minitest (2.5.1)
multi_json (1.7.7)
nokogiri (1.6.0)

I've been racking my brain for an hour now trying to figure out what can possibly be wrong... Please help!

我已经绞尽脑汁一个小时了,试图找出可能是什么问题......请帮忙!

Edit:

编辑:

Here's a more verbose error output:

这是一个更详细的错误输出:

An error occurred while installing nokogiri (1.6.0), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.0'` succeeds before bundling.
Bundler::InstallError: An error occurred while installing nokogiri (1.6.0), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.0'` succeeds before bundling.
/Library/Ruby/Gems/1.8/gems/bundler-1.3.5/lib/bundler/installer.rb:130:in `install_gem_from_spec'
/Library/Ruby/Gems/1.8/gems/bundler-1.3.5/lib/bundler/installer.rb:91:in `run'
/Library/Ruby/Gems/1.8/gems/bundler-1.3.5/lib/bundler/installer.rb:90:in `run'
/Library/Ruby/Gems/1.8/gems/bundler-1.3.5/lib/bundler/installer.rb:14:in `install'
/Library/Ruby/Gems/1.8/gems/bundler-1.3.5/lib/bundler/cli.rb:247:in `install'
/Library/Ruby/Gems/1.8/gems/bundler-1.3.5/lib/bundler/vendor/thor/task.rb:27:in `__send__'
/Library/Ruby/Gems/1.8/gems/bundler-1.3.5/lib/bundler/vendor/thor/task.rb:27:in `run'
/Library/Ruby/Gems/1.8/gems/bundler-1.3.5/lib/bundler/vendor/thor/invocation.rb:120:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/bundler-1.3.5/lib/bundler/vendor/thor.rb:344:in `dispatch'
/Library/Ruby/Gems/1.8/gems/bundler-1.3.5/lib/bundler/vendor/thor/base.rb:434:in `start'
/Library/Ruby/Gems/1.8/gems/bundler-1.3.5/bin/bundle:20
/Library/Ruby/Gems/1.8/gems/bundler-1.3.5/lib/bundler/friendly_errors.rb:3:in `with_friendly_errors'
/Library/Ruby/Gems/1.8/gems/bundler-1.3.5/bin/bundle:20
/usr/bin/bundle:19:in `load'
/usr/bin/bundle:19

采纳答案by wikichen

Turned out I was using the default system Ruby (and thus installing all the gems there in /Library/Ruby/Gems) even though rbenv points to ruby-1.9.3 so that's why Nokogiri was complaining.

结果我使用的是默认系统 Ruby(因此在 中安装了所有 gem /Library/Ruby/Gems),即使 rbenv 指向 ruby​​-1.9.3 所以这就是 Nokogiri 抱怨的原因。

Fixed this by adding this to $PATH, so rbenv loads before the system ruby:

通过将其添加到 $PATH 来修复此问题,因此 rbenv 在系统 ruby​​ 之前加载:

export PATH="$HOME/.rbenv/bin:$PATH"

export PATH="$HOME/.rbenv/bin:$PATH"

回答by Edouard

I'm using Mac OSX (El Capitan) and it appears to be related to Xcode Developer Tools. I ran xcode-select --installin my working directory, then reran bundle installcommand and it all worked fine after that ^^.

我正在使用 Mac OSX (El Capitan),它似乎与 Xcode Developer Tools 相关。我xcode-select --install在我的工作目录中运行,然后重新运行bundle install命令,之后一切正常 ^^。

Hope this could help someone.

希望这可以帮助某人。

回答by Phil

I ran into this error and this is what worked for me:

我遇到了这个错误,这对我有用:

bundle config build.nokogiri --use-system-libraries
bundle install

The problem was with libxml:

问题在于libxml

libxml2 is missing.  Please locate mkmf.log to investigate how it is failing.

回答by Emmanuel

make sure you have the latest version of command line tools. if you're not sure just run xcode-select --installand this will pop up a nice gui to guide you through the installation process. you can alternatively check the mac app store to see if you have an update there waiting for you. the current version is Command Line Developer Tool for OS X 10.10so you can see if Yosemite hasn't got a problem with that. after getting the update, run sudo bundle installand you can have the latest version of nokogiri. good luck.

确保您拥有最新版本的命令行工具。如果你不确定就运行xcode-select --install,这会弹出一个很好的 gui 来指导你完成安装过程。您也可以查看 mac 应用商店,看看是否有更新等着您。当前版本是Command Line Developer Tool for OS X 10.10这样你可以看看优胜美地是否没有问题。获得更新后,运行sudo bundle install即可获得最新版本的nokogiri。祝你好运。

回答by Jesus Garcia

Try using an older version of nokogiri, it worked for me

尝试使用旧版本的 nokogiri,它对我有用

gem 'nokogiri', '1.5.9'

宝石“nokogiri”,“1.5.9”

回答by Madis

If fellow googler is using linux (ubuntu) then installing deb package zlib1g-dev helped

如果 googler 同事正在使用 linux (ubuntu),那么安装 deb 包 zlib1g-dev 会有所帮助

回答by Aye Mon Chit

The following worked for me:

以下对我有用:

gem install nokogiri -- --use-system-libraries

回答by Esa M?kinen

Install older version with this command:gem install nokogiri -v 1.5.5

使用以下命令安装旧版本:gem install nokogiri -v 1.5.5

回答by Bruno Ramos

You just need to install Homebrewin your macOS

你只需要在你的 macOS 中安装Homebrew

Run on terminal /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

在终端上运行 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"