Ruby-on-rails 不兼容的库版本:nokogiri.bundle 需要 11.0.0 或更高版本,但 libxml2.2.dylib

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18818926/
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:43:23  来源:igfitidea点击:

Incompatible library version: nokogiri.bundle requires version 11.0.0 or later, but libxml2.2.dylib

ruby-on-railsrspec

提问by user2002730

I'm getting this error when trying to run rspec in Hartl's tutorial. I googled the error, but it's never for the specific version and the fixes don't actually fix my problem.

尝试在 Hartl 的教程中运行 rspec 时遇到此错误。我在谷歌上搜索了错误,但它从来都不是针对特定版本的,而且修复程序实际上并没有解决我的问题。

/Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-1.6.0/lib/nokogiri.rb:28:in `require': dlopen(/Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-           1.6.0/lib/nokogiri/nokogiri.bundle, 9): Library not loaded:    /Users/Jimbo/.bundler/tmp/22862/gems/nokogiri-1.6.0/ports/i686-apple-   darwin11/libxml2/2.8.0/lib/libxml2.2.dylib (LoadError)
Referenced from: /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-  1.6.0/lib/nokogiri/nokogiri.bundle
Reason: Incompatible library version: nokogiri.bundle requires version 11.0.0 or later, but libxml2.2.dylib provides version 10.0.0 - /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-1.6.0/lib/nokogiri/nokogiri.bundle
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-1.6.0/lib/nokogiri.rb:28:in `<top (required)>'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara.rb:2:in `require'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara.rb:2:in `<top (required)>'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'

回答by Ryan Linton

I suggest you first uninstall Nokogiri using:

我建议您首先使用以下方法卸载 Nokogiri:

sudo gem uninstall nokogiri

Then install Nokogiri using rubygems:

然后使用 ruby​​gems 安装 Nokogiri:

gem install nokogiri

If that doesn't work, there's an open issueon Nokogiri to support libxml 2.9.0 and later. There's a libxml2-2.9.1 branchthat was started in preparation for the next release of libxml2.

如果这不起作用,Nokogiri 上有一个未解决的问题以支持 libxml 2.9.0 及更高版本。已经启动了一个libxml2-2.9.1 分支,为下一版本的 libxml2 做准备。

Then try pulling from that branch in your Gemfile like this:

然后尝试从您的 Gemfile 中的该分支中提取,如下所示:

gem "nokogiri", github: "sparklemotion/nokogiri", branch: "libxml2-2.9.1"

or install an older version of libxml2.

或安装旧版本的 libxml2。

If that still doesn't work you may also want to try the suggestions here: What to do if libxml2 is being a jerk.

如果这仍然不起作用,您可能还想尝试这里的建议:如果 libxml2 是个混蛋,该怎么办。

回答by schmierkov

Not sure if it helps anyone, but I could just get nokogiri installed by using system libs

不确定它是否对任何人有帮助,但我可以使用系统库安装 nokogiri

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

回答by neuromantix

If you have Homebrew installed, try this. It solves the issue with the "Parsing documentation for nokogiri-1.6.1" hang. This worked for me.

如果你安装了 Homebrew,试试这个。它解决了“解析 nokogiri-1.6.1 的文档”挂起的问题。这对我有用。

gem uninstall nokogiri libxml-ruby

It'll ask you a series of questions based on how much of it you want to uninstall, answer "yes" or "[y]" to all.

它会根据您要卸载的内容问您一系列问题,对所有人回答“是”或“[y]”。

brew update
brew uninstall libxml2
brew install libxml2 --with-xml2-config
brew link --force libxml2
brew install libxslt 
brew link --force libxslt 

gem install nokogiri --no-rdoc --no-ri 

Then, in your project file:

然后,在您的项目文件中:

bundle install 

回答by Shepmaster

Your error message says:

您的错误消息说:

nokogiri.bundle requires version 11.0.0 or later, but libxml2.2.dylib provides version 10.0.0

nokogiri.bundle 需要 11.0.0 或更高版本,但 libxml2.2.dylib 提供 10.0.0 版本

This makes me think that your gem actually requires a version of libxml that is newerthan your system version. How have you installed libxml2? If you have homebrew installed, you might want to try upgrading it with

这让我认为您的 gem 实际上需要一个比您的系统版本更新的 libxml版本。你是如何安装 libxml2 的?如果您安装了自制软件,您可能想尝试使用以下命令升级它

brew update
brew upgrade

I was able to install Nokogiri 1.6.0 with Ruby 2.0.0p247 on OS X 10.9, and then require it in IRb. I double checked with Homebrew, and it is actually keg-only. However, Nokogiri seems to install its own version into gems/nokogiri-1.6.0/ports. On my machine, it is under x86_64-apple-darwin13.0.0.

我能够在 OS X 10.9 上使用 Ruby 2.0.0p247 安装 Nokogiri 1.6.0,然后在 IRb 中需要它。我仔细检查了 Homebrew,它实际上是keg-only。但是,Nokogiri 似乎将自己的版本安装到gems/nokogiri-1.6.0/ports. 在我的机器上,它在 x86_64-apple-darwin13.0.0 下。

回答by vaughanos

Reinstalling the gem didn't work for me, nor did pulling the particular branch.

重新安装 gem 对我不起作用,也没有拉动特定的分支。

It's not ideal, but I found that rolling back to 1.5.9 solved the issue.

这并不理想,但我发现回滚到 1.5.9 解决了这个问题。

回答by Paulo Cheque

First, check your version of libxml:

首先,检查您的 libxml 版本:

otool -L /usr/lib/libxml2.2.dylib

It can return

它可以返回

/usr/local/opt/libxml2/lib/libxml2.2.dylib (compatibility version 11.0.0, current version 11.0.0)

or

或者

/usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.9.0)

Then you can try reinstalling libxml to upgrade it:

然后你可以尝试重新安装libxml来升级它:

brew uninstall libxml2 libxslt
brew install libxml2 libxslt

After that, try to recompile your package:

之后,尝试重新编译您的包:

make clean
./configure
make
sudo make install

回答by Fábio BC Souza

First gem uninstall nokogiriSecond install nokogirithird restart terminal

第一个gem uninstall nokogiri第二install nokogiri个 第三个重启终端

be happy

要开心

回答by Fernando Osorto

Try the following inside your project directory.

在您的项目目录中尝试以下操作。

gem uninstall nokogiri

If there are more than one versions installed, a prompt will appear asking which version to remove. use the last option that reads "All versions".

如果安装了多个版本,则会出现一个提示,询问要删除哪个版本。使用最后一个选项“所有版本”。

Next, run bundle installinside your project directory. once it finishes installing the needed gems you should be good to go.

接下来,bundle install在您的项目目录中运行。一旦完成安装所需的 gem,您就可以开始使用了。

In my case, I hit the last option "All versions" as it doesn't hurt my project but it is possible that you might need the other versions based on different projects.

就我而言,我点击了最后一个选项“所有版本”,因为它不会影响我的项目,但您可能需要基于不同项目的其他版本。