简体   繁体   English

在 El Capitan 上安装 Nokogiri (1.6.7) 时出错

[英]Error while installing Nokogiri (1.6.7) on El Capitan

One of my developers have updated Nokogiri, and when pulling the updated Gemfile my bundle install fails.我的一位开发人员更新了 Nokogiri,当拉取更新的 Gemfile 时,我的bundle install失败。

➜  my-project git:(master) bundle install
Fetching source index from https://rubygems.org/
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.3
Using thread_safe 0.3.5
Using tzinfo 1.2.2
Using activesupport 4.2.3
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.0.0

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/me/.rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb --use-system-libraries
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** 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=/Users/me/.rvm/rubies/ruby-2.1.2/bin/ruby
  --help
  --clean
  --use-system-libraries
  --with-zlib-dir
  --without-zlib-dir
  --with-zlib-include
  --without-zlib-include=${zlib-dir}/include
  --with-zlib-lib
  --without-zlib-lib=${zlib-dir}/lib
  --with-xml2-dir
  --without-xml2-dir
  --with-xml2-include
  --without-xml2-include=${xml2-dir}/include
  --with-xml2-lib
  --without-xml2-lib=${xml2-dir}/lib
  --with-libxml-2.0-config
  --without-libxml-2.0-config
  --with-pkg-config
  --without-pkg-config
  --with-xslt-dir
  --without-xslt-dir
  --with-xslt-include
  --without-xslt-include=${xslt-dir}/include
  --with-xslt-lib
  --without-xslt-lib=${xslt-dir}/lib
  --with-libxslt-config
  --without-libxslt-config
  --with-exslt-dir
  --without-exslt-dir
  --with-exslt-include
  --without-exslt-include=${exslt-dir}/include
  --with-exslt-lib
  --without-exslt-lib=${exslt-dir}/lib
  --with-libexslt-config
  --without-libexslt-config

extconf failed, exit code 1

Gem files will remain installed in /Users/me/.rvm/gems/ruby-2.1.2@my-project/gems/nokogiri-1.6.7 for inspection.
Results logged to /Users/me/.rvm/gems/ruby-2.1.2@my-project/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.7/gem_make.out
An error occurred while installing nokogiri (1.6.7), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.7'` succeeds before bundling.

As suggested in " Failing to install Nokogiri gem " I have unsuccessfully tried to run:正如“ 无法安装 Nokogiri gem ”中所建议的,我尝试运行失败:

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

As suggested in " Failing to install Nokogiri gem " I also tried:正如“ 无法安装 Nokogiri gem ”中所建议的,我也尝试过:

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

and:和:

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

My OS version is El Capitan 10.11.2, and I have checked that the Xcode licence agreement has been accepted.我的操作系统版本是 El Capitan 10.11.2,我已经检查了 Xcode 许可协议是否已被接受。

Any ideas how to get the Nokogiri installation to succeed?任何想法如何让 Nokogiri 安装成功?

You should install xcode-select packages first, then try installing nokogiri again.您应该先安装xcode-select软件包,然后再次尝试安装 nokogiri。 Try these commands,试试这些命令,

xcode-select --install

then try然后尝试

gem install nokogiri

with whatever Nokogiri version you want.使用您想要的任何 Nokogiri 版本。

Nokogiri depends on multiple libraries like libxslt, libxml and zlib. Nokogiri 依赖于多个库,如 libxslt、libxml 和 zlib。 Dev versions (including source) of these should be installed before installing Nokogiri in any Linux distribution.在任何 Linux 发行版中安装 Nokogiri 之前,应安装这些的开发版本(包括源代码)。 For OS X, the above command should work I guess.对于 OS X,我猜上面的命令应该可以工作。

The actual solution is in the comments below.实际解决方案在下面的评论中。

Try this :试试这个 :

gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/

And then run然后运行

bundle update

I hope this could help you :)我希望这可以帮助你:)

I you're using homebrew to maintain libraries like libml on your mac, the following command on your mac might help:如果您在 mac 上使用自制软件来维护 libml 等库,则 mac 上的以下命令可能会有所帮助:


gem install nokogiri -v '1.6.8' -- --use-system-libraries --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2  --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib/

just ensure that the path for libxml is same as mine unless brew changes with the next version.只要确保 libxml 的路径与我的相同,除非 brew 在下一个版本中发生变化。 You can check this by running the below command:您可以通过运行以下命令来检查这一点:


brew info libxml2

Edit Updated work good with MacOS Sierra :编辑更新与 MacOS Sierra 配合良好:

xcode-select --install

Add gem "nokogiri", ">= 1.6.7.rc3" in your Gemfilegem "nokogiri", ">= 1.6.7.rc3"添加gem "nokogiri", ">= 1.6.7.rc3"

and then run然后运行

bundle install

try to:尝试:

apt-get install ruby-nokogiri
bundle install

Thank you for posting this!感谢您发布此信息! I finally got nokogirl to run with bundle install correctly for my app after running the following:在运行以下命令后,我终于让 nokogirl 为我的应用程序正确bundle installbundle install

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

Updating Xcode and Command Line Tools fixed all the errors for me.更新 Xcode 和命令行工具为我修复了所有错误。 After that I could install Nokogiri with gem install nokogiri and after that gem install rails worked fine.之后,我可以使用 gem install nokogiri 安装 Nokogiri,之后 gem install rails 工作正常。

The following steps worked for me以下步骤对我有用

ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

Run the following to install RVM and the latest stable version of Ruby:
\curl -L https://get.rvm.io | bash -s stable --ruby

Install the Ruby interpreter:

rvm install 2.1.0 --autolibs=enable

After that's finished installing, run:

source /Users/{your_user_name}/.rvm/scripts/rvm
Run:

ruby -v
ruby 2.1.0p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]


==> sudo gem install bundler
Fetching: bundler-1.14.6.gem (100%)
Successfully installed bundler-1.14.6
Parsing documentation for bundler-1.14.6
Installing ri documentation for bundler-1.14.6
Done installing documentation for bundler after 4 seconds
1 gem installed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM