Nokogiri 宝石安装错误

我知道有很多关于这颗宝石的问题,但是没有一个答案适合我。

当我在 SSH gem install nokogiri中运行时,我得到这个错误:

Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0... OK
Running patch with /home/user58952277/.gem/ruby/1.9.3/gems/nokogiri-1.6.2.1/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch...
Running 'patch' for libxml2 2.8.0... ERROR, review 'tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0/patch.log' to see what happened.
*** 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.

我的主机告诉我所有的库都已安装。 下面是执行 install nokogiri 命令后的完整日志:

Building native extensions.  This could take a while...
Building nokogiri using packaged libraries.
Building libxml2-2.8.0 for nokogiri with the following patches applied:
- 0001-Fix-parser-local-buffers-size-problems.patch
- 0002-Fix-entities-local-buffers-size-problems.patch
- 0003-Fix-an-error-in-previous-commit.patch
- 0004-Fix-potential-out-of-bound-access.patch
- 0005-Detect-excessive-entities-expansion-upon-replacement.patch
- 0006-Do-not-fetch-external-parsed-entities.patch
- 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
- 0008-Improve-handling-of-xmlStopParser.patch
- 0009-Fix-a-couple-of-return-without-value.patch
- 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
- 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT!  Nokogiri builds and uses a packaged version of libxml2.


If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:


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


If you are using Bundler, tell it to use the option:


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


However, note that nokogiri does not necessarily support all versions
of libxml2.


For example, libxml2-2.9.0 and higher are currently known to be broken
and thus unsupported by nokogiri, due to compatibility problems and
XPath optimization bugs.
************************************************************************
ERROR:  Error installing nokogiri:
ERROR: Failed to build gem native extension.


/opt/rubies/ruby-1.9.3/bin/ruby extconf.rb
Building nokogiri using packaged libraries.
checking for iconv.h... yes
checking for iconv_open() in iconv.h... yes
Building libxml2-2.8.0 for nokogiri with the following patches applied:
- 0001-Fix-parser-local-buffers-size-problems.patch
- 0002-Fix-entities-local-buffers-size-problems.patch
- 0003-Fix-an-error-in-previous-commit.patch
- 0004-Fix-potential-out-of-bound-access.patch
- 0005-Detect-excessive-entities-expansion-upon-replacement.patch
- 0006-Do-not-fetch-external-parsed-entities.patch
- 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
- 0008-Improve-handling-of-xmlStopParser.patch
- 0009-Fix-a-couple-of-return-without-value.patch
- 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
- 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT!  Nokogiri builds and uses a packaged version of libxml2.


If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:


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


If you are using Bundler, tell it to use the option:


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


However, note that nokogiri does not necessarily support all versions
of libxml2.


For example, libxml2-2.9.0 and higher are currently known to be broken
and thus unsupported by nokogiri, due to compatibility problems and
XPath optimization bugs.
************************************************************************
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0... OK
Running patch with /home/user58952277/.gem/ruby/1.9.3/gems/nokogiri-1.6.2.1/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch...
Running 'patch' for libxml2 2.8.0... ERROR, review 'tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0/patch.log' to see what happened.
*** 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=/opt/rubies/ruby-1.9.3/bin/ruby
--help
--clean
--use-system-libraries
--enable-static
--disable-static
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--enable-cross-build
--disable-cross-build
/home/user58952277/.gem/ruby/1.9.3/gems/mini_portile-0.6.0/lib/mini_portile.rb:279:in `block in execute': Failed to complete patch task (RuntimeError)
from /home/user58952277/.gem/ruby/1.9.3/gems/mini_portile-0.6.0/lib/mini_portile.rb:271:in `chdir'
from /home/user58952277/.gem/ruby/1.9.3/gems/mini_portile-0.6.0/lib/mini_portile.rb:271:in `execute'
from extconf.rb:282:in `block in patch'
from extconf.rb:279:in `each'
from extconf.rb:279:in `patch'
from /home/user58952277/.gem/ruby/1.9.3/gems/mini_portile-0.6.0/lib/mini_portile.rb:108:in `cook'
from extconf.rb:253:in `block in process_recipe'
from extconf.rb:154:in `tap'
from extconf.rb:154:in `process_recipe'
from extconf.rb:419:in `<main>'
55059 次浏览

最后,这个问题是由 nokogiri 自己引起的,因为它自己的 libxml2与某些系统不兼容。
所以要安装 nokogiri,我必须告诉它应该使用系统库。

我通过以下方式手动安装:

gem install nokogiri -v 1.6.2.1 -- --use-system-libraries

而且效果很好,其他答案都没能解决。

由于未列出的构建依赖项,我遇到了同样的问题:

find ~/.rbenv/ -name patch.log

它表示:

没有找到命令

修正了这个问题:

sudo yum install -y patch

我在 OS X 约塞米蒂国家公园就是这么干的。

gem install nokogiri -v 1.6.5 -- --use-system-libraries

在 OSX Yosemite 上,我在一个终端上做了 xcode-select --install。之后,bundle和那个宝石一起工作得很好。

最后,经过一番努力,下面的方法对我很有效(OS X 10.8.5,macports)

/opt/local/bin/gem install nokogiri -v 1.6.6.2 -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/libxml2 --with-xml2-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib

以下是我在 OS X 10.10.3优胜美地上的成果:

sudo gem install nokogiri -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --with-xml2-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib

这对我很有效:

sudo gem install nokogiri -v 'versionNumber'  -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-include=/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --with-xml2-lib=/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/lib

这对我在 Windows7家庭基本64位:

gem install nokogiri -v 1.6.2.1 -- --use-system-libraries

2020年4月6日更新:

MacOS Catalina 10.15

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libxml2/

MacOS Mojave 10.14

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/libxml2/

MacOS High Sierra 10.13

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/libxml2/

MacOS Sierra 10.12:

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2/

OS X El Capitan 10.11

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/

如果您没有权限,请考虑添加 sudo


由于某些原因,苹果的 Yosemite 版本的 OSX 没有一个系统可访问的 libxml2安装。Nokogiri 需要这样才能编译,幸运的是 Xcode 有一个与之捆绑的 libxml2版本ーー我们只需在安装 gem 时指定它。正确安装 Nokogiri 非常重要,因为目前 Rails 4.2.1。Rc4会自动尝试安装它,您会感到疼痛。

查看这篇文章获得更多信息。

在 Mac OS El Capitan 中安装 Nokogiri:

brew install libxml2 bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2"

bundle install

对我有用:)

就像 Wongzigii说的那样,install 命令可以在 macOS Sierra 中使用这些标志

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2/

现在的答案对我来说都不管用(我用的是 Ubuntu 16.04,不是 Mac)。

然而,通过遵循 Nokogiri 网站中的说明和这一部分,达到了目的:

# See http://www.nokogiri.org/tutorials/installing_nokogiri.html#ubuntu___debian
sudo apt-get install build-essential patch
sudo apt-get install ruby-dev zlib1g-dev liblzma-dev

注意,我从2009年就开始使用 Nokogiri 了,安装它总是有困难。任何进一步的评论可能不符合《安全与合作条例》 :)

我正在使用 MacOS Sierra。

去了 Nokogiri 的档案室,看到了这个:

在 MAC OSX 上

安装应该使用 Nokogiri 提供的 libxml2和 libxslt。

首先,确保你有 RubyGems 和 xcode 命令行工具的最新版本:

1 gem update --system

2 xcode-select --install

然后安装 nokogiri:

1 gem install nokogiri

Nokogiri 没有在我的 OSX Sierra 机器上找到 Xcode 库,直到我运行:

sudo xcodebuild -license accept

在我的例子中,我使用的是 Mac OSX Mojave,并且必须安装这里描述的一个包: https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes#3035624

以下是通往该软件包的路径: /Library/Developer/CommandLineTools/Packages/macOS _ SDK _ headers _ for _ macOS _ 10.14. pkg/Library/Developer/CommandLineTools/Packages/macOS _ SDK _ headers _ for _ macOS _ 10.14. pkg

安装完成后,安装没有任何问题。

我费了好大劲才弄明白这个问题,然后花了几个小时跟踪这些线索,研究人们正在尝试的东西。一点用都没有。这个溢出页面上的所有东西都没有帮助,所以我是这样解决的:

如果您将您的机器用于其他不在 ruby中的开发项目。您可能需要检查其他语言的包管理器安装。更重要的是-您可能想检查其他 c 编译器安装-即 clang

在我的例子中,我已经安装了 anaconda/conda(python),这取代了我的 .bash_profile中的一些路径,使用 clang作为主 c 编译器,而 xcode command line toolsrebenv都是使用早些时候通过 Homebrew 安装的 gcc

我删除了 anaconda(using anaconda-clean)clang安装,然后尝试捆绑。我就是那时候拿到 missing libxml2的。然后,我通过自制 REINSTALLED libxml2,以确保符号链接将通过 homebrew重做,并遵循指示,以添加适当的 export flags到我的 ~/bash_profile文件。

成功捆绑。原因是,gems 现在与我在该项目中使用的红宝石版本捆绑在同一个编译器中。

对于像我们许多人一样的通晓多种语言的开发机器来说,Docker 会让这个问题变得不成问题。

注意了。

第一步:

brew install libxml2

第二步:

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

第三步: 那就试试

捆绑式安装捆绑式安装

如果使用 bundler,请先运行以下命令:

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