Ruby-on-rails Nokogiri 安装失败 -libxml2 丢失

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

Nokogiri installation fails -libxml2 is missing

ruby-on-railsrubyrubygems

提问by Rohit A.

I always worked my way around Nokogiri installation issues by following the documentation in the "Installing Nokogiri" tutorial.

我总是按照“安装 Nokogiri”教程中的文档来解决 Nokogiri 安装问题。

But this time, even after installing all the dependencies, Nokogiri hasn't been installed. I get the following error:

但这一次,即使安装了所有依赖项,也没有安装 Nokogiri。我收到以下错误:

libxml2 is missing.  please visit <http://nokogiri.org/tutorials/installing_nokogiri.html>

I tried installing it by specifying the libxml2 and libxslt directories:

我尝试通过指定 libxml2 和 libxslt 目录来安装它:

sudo gem install nokogiri -- --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib --with-xslt-dir=/usr/

but it returned the same error.

但它返回了相同的错误。

I followed all the other related Stack Overflow articles and none helped. Does anyone have a solution?

我关注了所有其他相关的 Stack Overflow 文章,但没有任何帮助。有没有人有办法解决吗?

回答by Ryan

You may actually need to install both of these packages

您实际上可能需要安装这两个软件包

sudo apt-get install libxslt-dev libxml2-dev

回答by Erik Peterson

First, install the dependencies:

首先,安装依赖项:

sudo apt-get install libxslt-dev libxml2-dev

If you still receive the error, you may be missing a compiler toolchain:

如果您仍然收到错误消息,则您可能缺少编译器工具链:

sudo apt-get install build-essential

You'll get the "libxml2 is missing" error if you're missing a build toolchain (at least I ran into this issue on Debian Lenny).

如果您缺少构建工具链(至少我在 Debian Lenny 上遇到了这个问题),您将收到“缺少 libxml2”错误。

The Nokogiri build test-compiles a libxml2 header file to verify that it is present, however, it doesn't differentiate between "libxml2 is missing" and "a compiler to test libxml2 is missing".

Nokogiri 构建测试编译 libxml2 头文件以验证它是否存在,但是,它不区分“缺少 libxml2”和“缺少用于测试 libxml2 的编译器”。

回答by Eduardo

In Mac OS X (Mavericks), installing the libraries with brewand setting NOKOGIRI_USE_SYSTEM_LIBRARIES=1before installing the gem did the trick for me.

在 Mac OS X (Mavericks) 中,在安装 gem 之前使用brew和设置NOKOGIRI_USE_SYSTEM_LIBRARIES=1安装库对我来说很有效。

Summarising:

总结:

  • If previously installed, uninstall the gem:

    gem uninstall nokogiri
    
  • Use Homebrew to install libxml2, libxsltand libiconv:

    brew install libxml2 libxslt libiconv
    
  • Install the gem specifying the paths to the libraries to be linked against:

    NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"
    
  • 如果之前安装过,请卸载 gem:

    gem uninstall nokogiri
    
  • 使用 Homebrew 安装libxml2,libxsltlibiconv

    brew install libxml2 libxslt libiconv
    
  • 安装 gem,指定要链接的库的路径:

    NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"
    

回答by Sojoodi

I just had the same issue on Fedora 13. After a frustrating and unsuccessful search to make

我刚刚在 Fedora 13 上遇到了同样的问题。经过令人沮丧和失败的搜索之后

gem install nokogiri

work for me, I was able to install it and get around the libxml2 error via yum.

对我来说有效,我能够安装它并通过yum.

Simply install the gem via yuminstead of the gemcommand:

只需通过yum以下gem命令安装 gem :

su
yum search rubygem-nokogiri   #this find the proper package name
yum install rubygem-nokogiri.i686

This helped me find the right answer for Fedora and, as I am using RVM for Ruby package management,

这帮助我找到了 Fedora 的正确答案,并且当我使用 RVM 进行 Ruby 包管理时,

yum install rubygem-nokogiri

will pull in all the Ruby gems and dependencies into the system, not into my RVM environment, and in my experience that leads to a very frustrating and humbling experience.

会将所有 Ruby gems 和依赖项引入系统,而不是引入我的 RVM 环境,根据我的经验,这会导致非常令人沮丧和谦卑的体验。

So, taking your find of the Nokogiri yum gem you can use:

因此,找到您可以使用的 Nokogiri yum gem:

yum provides  rubygem-nokogiri

and get a list of the dependencies for rubygem-Nokogiri which showed me the libraries that were missing. After that I ran:

并获取 ruby​​gem-Nokogiri 的依赖项列表,它向我展示了丢失的库。之后我跑了:

yum install libxml2-devel libxslt libxslt-devel

Now Nokogiri compiles in Fedora and Nokogiri installs. D'oh!, we need the headers to compile Nokogiri from the devel libraries.

现在 Nokogiri 在 Fedora 中编译并安装 Nokogiri。天哪!,我们需要头文件来从 devel 库编译 Nokogiri。

回答by pduersteler

You usually need development files for building gems. Try:

您通常需要开发文件来构建 gem。尝试:

sudo apt-get install libxslt-dev libxml2-dev

(I just saw that Eric suggested the same in a comment.)

(我刚刚看到 Eric 在评论中提出了同样的建议。)

回答by rilla

In Mac OS X (Mavericks) if none of these solutions work, try:

在 Mac OS X (Mavericks) 中,如果这些解决方案都不起作用,请尝试:

ARCHFLAGS="-arch x86_64" gem install nokogiri

or

或者

ARCHFLAGS="-arch i386" gem install nokogiri

depending on your system's architecture.

取决于您的系统架构。

回答by hohner

It will be:

这将是:

sudo yum install -y libxml2 libxml2-devel

on RHEL servers.

在 RHEL 服务器上。

回答by Chloe

I was able to get this installed with Chocolatey, Windows 8.1 x64, and DevKit x64.

我能够在Chocolatey、Windows 8.1 x64 和 DevKit x64 上安装它。

cinst libxml2
cinst libxslt
cinst libiconv

gem install nokogiri -- 
  --with-xml2-include=C:\Chocolatey\lib\libxml2.2.7.8.7\build\native\include 
  --with-xml2-lib=C:\Chocolatey\lib\libxml2.redist.2.7.8.7\build\native\bin\v110\x64\Release\dynamic\cdecl 
  --with-iconv-include=C:\Chocolatey\lib\libiconv.1.14.0.11\build\native\include 
  --with-iconv-lib=C:\Chocolatey\lib\libiconv.redist.1.14.0.11\build\native\bin\v110\x64\Release\dynamic\cdecl 
  --with-xslt-include=C:\Chocolatey\lib\libxslt.1.1.28.0\build\native\include 
  --with-xslt-lib=C:\Chocolatey\lib\libxslt.redist.1.1.28.0\build\native\bin\v110\x64\Release\dynamic

You'll have to verify the version number in the paths are correct.

您必须验证路径中的版本号是否正确。

You may possibly need to add Microsoft's NuGet repository:

您可能需要添加 Microsoft 的 NuGet 存储库:

-Source "https://go.microsoft.com/fwlink/?LinkID=230477"

回答by sobstel

At macOS none of above/below had really worked for me until I explicitly provided XCode libxml2 path to --with-xml2-include.

在 macOS 上,在我明确提供 XCode libxml2 到--with-xml2-include.

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

回答by Simone

I was able to install Nokogiri 1.6.5 on Fedora 20 by doing:

通过执行以下操作,我能够在 Fedora 20 上安装 Nokogiri 1.6.5:

export NOKOGIRI_USE_SYSTEM_LIBRARIES=true

Then running:

然后运行:

gem install nokogiri