Gem 发现 Ruby 2.4.0 安装 Nokogiri 新问题 - Please install either `pkg-config` or the pkg-config gem

huacnlee · 发布于 2016年12月13日 · 最后由 nouse 回复于 2017年1月22日 · 644 次阅读
2
    current directory: /Users/jason/.rvm/gems/ruby-2.4.0-rc1/gems/nokogiri-1.6.8.1/ext/nokogiri
/Users/jason/.rvm/rubies/ruby-2.4.0-rc1/bin/ruby -r ./siteconf20161213-20764-fn51a4.rb 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.
pkg-config could not be used to find libxml-2.0
Please install either `pkg-config` or the pkg-config gem per

    gem install pkg-config -v "~> 1.1.7"

pkg-config could not be used to find libxslt
Please install either `pkg-config` or the pkg-config gem per

    gem install pkg-config -v "~> 1.1.7"

pkg-config could not be used to find libexslt
Please install either `pkg-config` or the pkg-config gem per

    gem install pkg-config -v "~> 1.1.7"

ERROR: cannot discover where libxml2 is located on your system. please make sure `pkg-config` is installed.
*** 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
    --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/jason/.rvm/rubies/ruby-2.4.0-rc1/bin/$(RUBY_BASE_NAME)
    --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

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/jason/.rvm/gems/ruby-2.4.0-rc1/extensions/x86_64-darwin-16/2.4.0/nokogiri-1.6.8.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/jason/.rvm/gems/ruby-2.4.0-rc1/gems/nokogiri-1.6.8.1 for inspection.
Results logged to /Users/jason/.rvm/gems/ruby-2.4.0-rc1/extensions/x86_64-darwin-16/2.4.0/nokogiri-1.6.8.1/gem_make.out

An error occurred while installing nokogiri (1.6.8.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.8.1'` succeeds before bundling.

以往的经验是系统安装 libxml2 和 libxslt 就可以了,今天升级 Ruby 2.4.0-rc1 以后发现居然还需要安装 pkg-config 这个 Gem,第一次遇到额,这是新东西么?

看上面的错误提示,执行一下这个就好了:

gem install pkg-config -v "~> 1.1.7"
共收到 5 条回复
1680
justin · #1 · 2016年12月13日

原来 Mac 下 xcode-select --install 就会安装 pkg-config

15139
msg7086 · #2 · 2016年12月14日

因为你没装 pkg-config

Deb: apt-get install pkg-config

Mac: brew install pkg-config

试试。

2
huacnlee · #3 · 2016年12月14日

实际上我是装过的

273
ruby_sky · #4 · 2017年1月20日

说实在,安装Nokogiri真是纠结:

gem install nokogiri -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-include=/usr/local/opt/libxml2/include/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib
775
nouse · #5 · 2017年1月22日

That's why you need docker on Mac.

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册