运行bundle install时出现Nokogiri错误

时间:2013-06-20 01:58:54

标签: ruby-on-rails ruby rubygems nokogiri rbenv

尝试运行克隆的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.

但这是rbenv version的输出:

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

运行gem list时,我得到:

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

我现在已经绞尽脑汁一小时了,试图找出可能出错的地方......请帮忙!

编辑:

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

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

9 个答案:

答案 0 :(得分:27)

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

希望这可以帮助某人。

答案 1 :(得分:18)

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

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

问题在于libxml

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

答案 2 :(得分:12)

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

通过将此添加到$ PATH来解决此问题,因此rbenv在系统ruby之前加载:

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

答案 3 :(得分:11)

确保您拥有最新版本的命令行工具。如果你不确定只是运行xcode-select --install,这会弹出一个很好的gui来指导你完成安装过程。您也可以检查mac app store以查看是否有等待您的更新。当前版本为Command Line Developer Tool for OS X 10.10,因此您可以看到Yosemite是否遇到问题。获得更新后,运行sudo bundle install,您就可以获得最新版本的nokogiri。祝你好运。

答案 4 :(得分:5)

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

gem'nokogiri','1.5.9'

答案 5 :(得分:2)

以下对我有用:

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

答案 6 :(得分:1)

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

答案 7 :(得分:0)

您只需要在macOS中安装Homebrew

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

答案 8 :(得分:0)

在Ubuntu计算机上,以下是有关安装Nokogiri的文档建议:

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

https://nokogiri.org/tutorials/installing_nokogiri.html

我还必须: sudo apt-get install libxslt-dev libxml2-dev如此说明: https://stackoverflow.com/a/6277635/5656846