Error while installing Nokogiri (1.6.7) on El Capi

2019-01-21 05:41发布

One of my developers have updated Nokogiri, and when pulling the updated Gemfile my bundle install fails.

➜  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:

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

As suggested in "Failing to install Nokogiri gem" I also tried:

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.

Any ideas how to get the Nokogiri installation to succeed?

8条回答
虎瘦雄心在
2楼-- · 2019-01-21 05:56

Add gem "nokogiri", ">= 1.6.7.rc3" in your Gemfile

and then run

bundle install
查看更多
一纸荒年 Trace。
3楼-- · 2019-01-21 05:59

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 :)

查看更多
对你真心纯属浪费
4楼-- · 2019-01-21 06:04

You should install xcode-select packages first, then try installing nokogiri again. Try these commands,

xcode-select --install

then try

gem install nokogiri

with whatever Nokogiri version you want.

Nokogiri depends on multiple libraries like libxslt, libxml and zlib. Dev versions (including source) of these should be installed before installing Nokogiri in any Linux distribution. For OS X, the above command should work I guess.

The actual solution is in the comments below.

查看更多
Root(大扎)
5楼-- · 2019-01-21 06:04

Updating Xcode and Command Line Tools fixed all the errors for me. After that I could install Nokogiri with gem install nokogiri and after that gem install rails worked fine.

查看更多
女痞
6楼-- · 2019-01-21 06:05

try to:

apt-get install ruby-nokogiri
bundle install
查看更多
The star\"
7楼-- · 2019-01-21 06:18

I you're using homebrew to maintain libraries like libml on your mac, the following command on your mac might help:


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. You can check this by running the below command:


brew info libxml2
查看更多
登录 后发表回答