如何在 Mac OS Sierra 10.12 上安装 Nokogiri

How to install Nokogiri on Mac OS Sierra 10.12

我在 Mac OS Sierra 10.12 上安装 Nokogiri (1.6.8.1) 时遇到问题。

我尝试使用 brew install libxml2 libxslt,然后使用命令行选项引用安装目录,但没有帮助。

打开 Xcode,然后从菜单 XCode -> Preferences 更新您的命令行工具 (Xcode 8.0)。

然后做:

bundle config build.nokogiri --use-system-libraries=true --with-xml2-include="$(xcrun --show-sdk-path)"/usr/include/libxml2
bundle install

或者只是:

gem install nokogiri -v 1.6.8.1 -- --use-system-libraries=true --with-xml2-include="$(xcrun --show-sdk-path)"/usr/include/libxml2

这可能是 的重复...最新接受的答案是:

brew unlink xz; bundle install; brew link xz

重新链接 xz 可能没有必要...例如,如果您只是因为 the_silver_searcher(它直接链接到非符号链接库)而具有该依赖项。

更简单的解决方案是执行:

xcode-select --install
gem install nokogiri

更新

对于 Mojave,我使用 gem install nokogiri -v '1.6.6.2' -- --use-system-libraries

gem update --system
xcode-select --install
brew unlink xz
gem install nokogiri -v '1.6.8.1'
brew link xz

如果上述步骤未能解决问题,对我也有效的方法是 运行 brew doctor 并清理所有未编译的头文件。

类似于 yuяi 的回答和来自 Nokogiri 的帮助:

brew unlink xz
gem install nokogiri
brew link xz

http://www.nokogiri.org/tutorials/installing_nokogiri.html#mac_os_x

这适用于 1.7.0.1

首先尝试使用 Homebrew 安装 libxml2。

brew install libxml2

然后如果使用捆绑安装

bundle config build.nokogiri --use-system-libraries \
  --with-xml2-include=$(brew --prefix libxml2)/include/libxml2
bundle install

如果直接用gem安装

gem install nokogiri -- --use-system-libraries \
  --with-xml2-include=$(brew --prefix libxml2)/include/libxml2

如果您之前使用带有 bundle config build.nokogiri --use-system-libraries 的捆绑器安装了 nokogiri,此设置将仍然存在。如果你同时已经解决了你的 Xcode 设置(如 nokogiri 安装中的主要安装方法所建议的那样)那么你可能想尝试从捆绑器 bundle config --delete build.nokogiri 中删除该 fra 并再次尝试执行 bundle install.

对于中间商

gem 安装 nokogiri -v '1.8.2' -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX。 platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/libxml2/

首先从应用商店XCode安装

然后运行

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

然后运行

bundle install

这应该有效