Ruby-on-rails OS X Lion,尝试安装 Nokogiri - 缺少 libxml2

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

OS X Lion, Attempting Nokogiri install - libxml2 is missing

ruby-on-railsosx-lionnokogiri

提问by Sajeev Shanmuganandarajah

sudo gem install nokogiri
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

        /Users/sajeev86/.rvm/rubies/ruby-1.8.7-p352/bin/ruby extconf.rb
checking for libxml/parser.h... no
-----
libxml2 is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** 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.

I can't get Nokogiri to install. This has been taxing me for a while now. I've installed the dependencies via MacPorts and Homebrew as well.

我无法安装 Nokogiri。这已经让我负担了一段时间了。我也通过 MacPorts 和 Homebrew 安装了依赖项。

I've got a feeling the right directories are not pointed to each other? But haven't a clue how to fix.

我有一种感觉,正确的目录没有相互指向?但不知道如何修复。

回答by Eduardo

In Mavericks, installing the libraries with Homebrew and setting NOKOGIRI_USE_SYSTEM_LIBRARIES=1before installing the gem did the trick for me.

在 Mavericks 中,使用 Homebrew 安装库并NOKOGIRI_USE_SYSTEM_LIBRARIES=1在安装 gem 之前进行设置对我来说很有用。

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 Crates

Absolutely noneof the other answers here worked for me.

绝对没有其他答案对我有用。

On the latest version of Mavericks, the only method that succeeded for me was the following:

在最新版本的 Mavericks 上,对我来说唯一成功的方法如下:

$ brew install libxml2 libxslt libiconv
$ sudo gem install nokogiri -v '1.6.5' -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib

回答by Rememberer

Same issue happened to me on Lion. Took hours of reading posts, trying homebrew, macports, etc. When I found this postand read the contents of .rvm/gems/ruby-1.8.7-p358/gems/nokogiri-1.4.4/ext/nokogiri/mkmf.log, I saw:

我在 Lion 上也遇到了同样的问题。花了几个小时阅读帖子,尝试自制软件,macports 等。当我找到这篇文章并阅读 .rvm/gems/ruby-1.8.7-p358/gems/nokogiri-1.4.4/ext/nokogiri/mkmf 的内容时。日志,我看到:

find_header: checking for libxml/parser.h... -------------------- no

"/usr/bin/gcc-4.2 -E -I. -I/Users/me/.rvm/rubies/ruby-1.8.7-p358/lib/ruby/1.8/i686-darwin10.8.0 -I. -I-I-I/opt/local/include -I-I-I/usr/local/include -I-I-I/Users/me/.rvm/rubies/ruby-1.8.7-p358/include -I-I-I/usr/include -I-I-I/usr/include/libxml2 -I/opt/local/include/libxml2 -I/usr/local/include/libxml2 -I/Users/me/.rvm/rubies/ruby-1.8.7-p358/include/libxml2 -I-I/opt/local/include -I-I/usr/local/include -I-I/Users/me/.rvm/rubies/ruby-1.8.7-p358/include -I-I/usr/include -I-I/usr/include/libxml2 -I/opt/local/include -I/usr/local/include -I/Users/me/.rvm/rubies/ruby-1.8.7-p358/include -I/usr/include -I/usr/include/libxml2  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -g -O2  -fno-common -pipe -fno-common    -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline  conftest.c -o conftest.i"
checked program was:
/* begin */
1: #include <libxml/parser.h>
/* end */

However, gcc-4.2 didn't exist:

但是,gcc-4.2 不存在:

$ ls /usr/bin/gcc*
/usr/bin/gcc

Hence, I was able to solve the issue and get nokogiri to install by making a gcc-4.2 a symlink to gcc.

因此,我能够通过将 gcc-4.2 作为 gcc 的符号链接来解决该问题并安装 nokogiri。

sudo ln -s gcc gcc-4.2

回答by shinesecret

I ran into same issue for Mavrick and solution was the

我为 Mavrick 遇到了同样的问题,解决方案是

xcode-select --install

However that was not working as apple download page does not have that installer available publically. So if you want to have the command-line tools for Mavricks you need to have a paid account then only you will be able to install it. Once you install it you will not face this issue of Nokogiri.

但是,这不起作用,因为苹果下载页面没有公开提供该安装程序。因此,如果您想拥有 Mavricks 的命令行工具,您需要有一个付费帐户,然后只有您才能安装它。一旦你安装它,你就不会遇到 Nokogiri 的这个问题。

回答by ahmeij

Checking the url given in the error message (http://nokogiri.org/tutorials/installing_nokogiri.html) I think the question is what version of Homebrew are you using?

检查错误消息中给出的 url (http://nokogiri.org/tutorials/installing_nokogiri.html) 我认为问题是你使用的是什么版本的 Homebrew?

brew -v

I'd update to 0.8+

我会更新到 0.8+

brew update
brew upgrade

and then try the installation again:

然后再次尝试安装:

brew install libxml2 libxslt
brew link libxml2 libxslt
gem install nokogiri

回答by zires

brew install libxml2 libxslt 
gem install nokogiri -v '1.6.5' -- --use-system-libraries

回答by shilovk

As for me, it helps:

至于我,它有帮助:

brew install libxml2 libxslt

if permission denied sudo chown -R $USER /Library/Caches/Homebrew/

如果权限被拒绝 sudo chown -R $USER /Library/Caches/Homebrew/

sudo env ARCHFLAGS="-arch x86_64"

export NOKOGIRI_USE_SYSTEM_LIBRARIES=1

NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri

回答by Learning stats by example

On Yosemite I used:

在优胜美地我用过:

brew install libxml2 libxslt
sudo gem install nokogiri -v '1.6.5' -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib

Very close to some of the above commands but without the libconv

非常接近上面的一些命令,但没有 libconv

回答by user1136698

Late to the party, but in case anyone is still having this issue while using MacPorts:

聚会迟到,但万一有人在使用 MacPorts 时仍然遇到此问题:

Add the /include dir to your PATH in your .profile file so nokogiri knows where to find it.

将 /include 目录添加到 .profile 文件中的 PATH 中,以便 nokogiri 知道在哪里可以找到它。

e.g.

例如

MacPorts writes to your .profile file and adds the following line by default:

MacPorts 写入您的 .profile 文件并默认添加以下行:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

First, add the /include path like so:

首先,像这样添加 /include 路径:

export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/include/:$PATH

Then, run this from the same terminal window:

然后,从同一个终端窗口运行它:

source ~/.profile

(this tells your terminal to recheck the .profile file for any changes)

(这会告诉您的终端重新检查 .profile 文件是否有任何更改)

Finally, try installing the gem from the same terminal window.

最后,尝试从同一个终端窗口安装 gem。

sudo gem install nokogiri

回答by ericpeters0n

For my somewhat outdated system encountering the issues above, specifically:

对于我遇到上述问题的有点过时的系统,特别是:

FENG-SHUI:demo Eric$ brew install libxml2
==> Downloading ftp://xmlsoft.org/libxml2/libxml2-2.9.0.tar.gz
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
######################################################################## 100.0%
==> Patching patching file threads.c patching file xpath.c
==> ./configure --prefix=/usr/local/Cellar/libxml2/2.9.0 --without-python
==> make
==> make install
==> Caveats This formula is keg-only: so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in parallel can cause all kinds of trouble.

Generally there are no consequences of this for you. If you build your own software and it requires this formula, you'll need to add to your build variables:

    LDFLAGS:  -L/usr/local/opt/libxml2/lib
    CPPFLAGS: -I/usr/local/opt/libxml2/include

Error: Failed to create: /usr/local/opt/libxml2 
Things that depend on libxml2 will probably not build.
    ==> Summary /usr/local/Cellar/libxml2/2.9.0: 273 files, 11M, built in 2.0 minutes 

FENG-SHUI:demo Eric$ brew install libxml2 libxslt 
Error: libxml2-2.9.0 already installed 
Error: /usr/local/opt/libxml2 not present or broken Please reinstall libxml2. Sorry :(

This was the magic formula for getting libxml2 and libxslt happily running:

这是让 libxml2 和 libxslt 愉快地运行的神奇公式:

# latest version 2.9.0
brew install libxml2

# installing libxslt from source code
# get latest libxslt from ftp://xmlsoft.org/libxml2/libxslt-git-snapshot.tar.gz..
# then
./configure --prefix=/usr/local/Cellar/libxslt/1.1.28 --with-libxml-prefix=/usr/local/Cellar/libxml2/2.9.0
make
sudo make install

# installing nokogiri with this new compiled libs
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28

Thanks to this guy: https://gist.github.com/fabioyamate/443160

感谢这个人:https: //gist.github.com/fabioyamate/443160

Hope this helps someone!

希望这可以帮助某人!