nokogiri gem安装错误


68

我知道这个宝石有很多问题,但是没有答案对我有用。

当我在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>'

听起来像是/tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0/patch.log中有更多信息
Frederick Cheung

我还将检查mkmf.log文件以获取更多详细信息。
马克·托马斯

它说/opt/rubies/ruby-1.9.3/lib/ruby/1.9.1/mkmf.rb:381:in try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first.
Claudiu Creanga 2014年

因此它们没有按照我的主人所说的安装,对吗?
Claudiu Creanga 2014年

正确,您似乎需要编译器。
CWitty

Answers:


141

2020年4月6日更新:

macOS卡塔利娜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如果您没有权限,请考虑添加。


由于某种原因,Apple的Yosemite版本的OSX没有系统可访问的libxml2安装。Nokogiri要求使用它来进行编译,幸运的是Xcode捆绑了一个libxml2版本-我们只需要在安装gem时指定它即可。正确安装Nokogiri非常重要,因为截至目前,Rails 4.2.1.rc4会自动尝试安装它,您会感到痛苦。

查看此帖子以获取更多信息


谢谢,我已经找了很长时间了。
Stoic Alchemist

1
是的,这对我有用,但是被接受的答案无效。我正在运行El Capitan
Shawn Lauzon

1
这应该是正确的答案。已投票。请注意,对于Mac OS Sierra v.10.12用户,您需要将命令更改为:gem install nokogiri---use-system-libraries --with-xml2-include = / Applications / Xcode.app / Contents / Developer /平台/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2/
colemerrick

即使我在macOS Sierra上,我仍然需要使用“ 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权限的macOS Sierra中使用建议的一种,然后让我安装nokogiri和rails。非常感谢。
dnzprmksz

51

最后,问题是由nokogiri本身引起的,原因是它发行了自己的与某些系统不兼容的libxml2。
因此,要安装nokogiri,我必须告诉它应该使用系统库。

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

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

而且效果很好。其他答案没有解决。


3
我删除了带有特定版本的-v,它解决了类似的问题。
analyticsPierce

也可以使用Ubuntu 14.04 :)
Maria Ines Parnisari

在Ubuntu 15.10的另一个(?作弊)解决方案:sudo易于安装红宝石引入nokogiri
弗雷德里克Grosshans

对于RVM / rbenv用户@FrédéricGrosshans坏的解决方案
sunki

24

由于未列出的构建依赖性,我遇到了同样的问题。当我找到有问题的tmp目录时:

find ~/.rbenv/ -name patch.log

它说:

sh:补丁:找不到命令

修复了一个简单的问题:

sudo yum install -y patch

3
这帮助我在Amazon Linux上安装了Nokogiri!
johnsorrentino'3



3

这适用于OS X Yosemite。

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

3

当前答案对我没有任何帮助(我使用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,但始终无法安装它。任何进一步的评论可能都不符合SO条款和条件:)


3

在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

它对我有用:)


这在OSX Yosemite上为我工作。其他答案均无效。谢谢!
rayryeng

3

直到我运行,Nokogiri才在OSX Sierra机器上找不到Xcode库:

sudo xcodebuild -license accept


这是我的问题。我之前已经同意使用CLI工具,但是我只是通过app store.appprogrom对其进行了更新。我mkmf.log在错误输出中提到的文件中找到了提示。检查完文件后,我发现有错误消息:Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.。之后,Nokogiri可以正确安装。
Sgnl

2

这是在OS X 10.10.3 Yosemite上对我有用的东西:

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

2

就像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/


1

这对我有用:

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

1

我想出了很难的方法,花了几个小时来追踪面包屑,并阅读人们正在尝试的内容。没有任何帮助。溢出页面上的所有内容都无济于事,所以这是我解决此问题的方法:

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

在我的情况-我已经安装了anaconda/conda(python),这取代了一堆在我的路径,.bash_profile使用clang其中作为作为主要的C编译器xcode command line toolsrebenv全部使用gcc通过自制安装较早。

我删除anaconda(using anaconda-clean)clang安装,然后尝试捆绑。那是我遇到的missing libxml2问题。然后REINSTALLED libxml2,我通过自制程序以确保符号链接将被重做,homebrew并按照随后的说明将适当的内容添加export flags到我的~/bash_profile文件中。

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

对于像我假设的许多人那样的多语言开发机器,Docker会使其成为一个非问题。

所以抬头。


1

第1步:

brew install libxml2

第2步:

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

步骤3:然后尝试

捆绑安装


0

终于,经过艰苦的努力,以下内容对我有用(OS X 10.8.5,macports)。(我正在安装github页面,例如jekyll)

/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 


-2

我正在使用macOS Sierra。

去了nokogiri文档,并遵循以下步骤:

在MAC OSX上

使用Nokogiri提供的libxml2和libxslt进行安装应使用Just Work™。

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

1个 gem update --system

2 xcode-select --install

然后安装nokogiri:

1个 gem install nokogiri

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.