【问题标题】:Install Nokogiri on Yosemite 10.10.3Install Nokogiri on Yosemite 10.10.3
【发布时间】:2015-05-26 05:48:58
【问题描述】:

我有:

  • Mac OS X Yosemite 10.10.3
  • MacPorts(非 Brew)
  • 系统中的 Ruby 2(不是 RVM)

我想安装 Nokogiri 并尝试过:

port install nokogiri

得到:

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

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r
./siteconf20150323-30174-1mqhl4i.rb extconf.rb 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 packaged libraries. checking for gzdopen() in
-lz... yes checking for iconv... yes
************************************************************************ IMPORTANT NOTICE:

Building Nokogiri with a packaged version of libxml2-2.9.2 with the
following patches applied:
    - 0001-Revert-Missing-initialization-for-the-catalog-module.patch
    - 0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch

Team Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:

    gem install nokogiri -- --use-system-libraries
        [--with-xml2-config=/path/to/xml2-config]
        [--with-xslt-config=/path/to/xslt-config]

If you are using Bundler, tell it to use the option:

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

Note, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.
************************************************************************ Extracting libxml2-2.9.2.tar.gz into
tmp/x86_64-apple-darwin14/ports/libxml2/2.9.2... OK Running patch with
/Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2/ports/patches/libxml2/0001-Revert-Missing-initialization-for-the-catalog-module.patch...
Running 'patch' for libxml2 2.9.2... OK Running patch with
/Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2/ports/patches/libxml2/0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch...
Running 'patch' for libxml2 2.9.2... OK Running 'configure' for
libxml2 2.9.2... OK Running 'compile' for libxml2 2.9.2... ERROR,
review
'/Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2/ext/nokogiri/tmp/x86_64-apple-darwin14/ports/libxml2/2.9.2/compile.log'
to see what happened.
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    --help  --clean     --use-system-libraries  --enable-static
    --disable-static    --with-zlib-dir     --without-zlib-dir
    --with-zlib-include     --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib     --without-zlib-lib=${zlib-dir}/lib
    --enable-cross-build    --disable-cross-build
/Library/Ruby/Gems/2.0.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:279:in
`block in execute': Failed to complete compile task (RuntimeError)
    from
/Library/Ruby/Gems/2.0.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:271:in
`chdir'     from
/Library/Ruby/Gems/2.0.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:271:in
`execute'   from
/Library/Ruby/Gems/2.0.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:70:in
`compile'   from
/Library/Ruby/Gems/2.0.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:110:in
`cook'  from extconf.rb:278:in `block in process_recipe'    from
extconf.rb:177:in `tap'     from extconf.rb:177:in `process_recipe'     from
extconf.rb:475:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in
/Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2 for inspection. Results
logged to
/Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/nokogiri-1.6.6.2/gem_make.out

我试过了:

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

得到:

Building native extensions with: '--use-system-libraries' This could
take a while... ERROR:  Error installing nokogiri:  ERROR: Failed to
build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r
./siteconf20150323-34882-16v74a8.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. checking for xmlParseDoc()
in libxml/parser.h... no checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no
----- libxml2 is missing.  Please locate mkmf.log to investigate how it is failing.
-----
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/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   --with-xml2lib
    --without-xml2lib   --with-libxml2lib   --without-libxml2lib

extconf failed, exit code 1

Gem files will remain installed in
/Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2 for inspection. Results
logged to
/Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/nokogiri-1.6.6.2/gem_make.out

我试过了:

port install libxml2

得到:

--->  Computing dependencies for libxml2
--->  Cleaning libxml2
--->  Scanning binaries for linking errors
--->  No broken files found.

我还能做些什么来安装 Nokogiri?

【问题讨论】:

    标签: ruby macos gem nokogiri osx-yosemite


    【解决方案1】:

    因为 MacPorts(和其他类似的包管理器)在非标准位置安装包,它不能自动确定 libxml2 的路径。您第一次尝试中的警告提供了有关如何解决此问题的信息:

    gem install nokogiri -- --use-system-libraries
         [--with-xml2-config=/path/to/xml2-config]
         [--with-xslt-config=/path/to/xslt-config]
    

    你说你试过gem install nokogiri -- --use-system-librariesThe Nokogiri documentation 建议您需要添加以下两个选项之一:

    • --with-xml2-config - xml2-config 二进制文件的路径(尝试 which xml2-config
    • --with-xml2-dir - libxml2 基本安装目录的路径

    如果您在非标准位置安装了 libxml2 和/或 libxslt (读作“不是 /opt/local、/usr/local、/usr 或标准 Ruby 目录”),您可以使用命令行参数来安装 gem 命令润滑车轮。

    gem install nokogiri -- \
    --使用系统库\
    --with-xml2-dir=/path/to/dir \
    --with-xslt-dir=/path/to/dir

    This page 为各种包管理器提供适当的命令,包括 MacPorts:

    gem install nokogiri -- \
                --with-xml2-include=/opt/local/include/libxml2 \
                --with-xml2-lib=/opt/local/lib \
                --with-xslt-dir=/opt/local
    

    【讨论】:

    • ...你真的应该试试 Homebrew。 :)
    • This MacPorts user 报告 pkgconfig 在解决 Nokogiri 安装错误时很有用,但我认为这有点过头了。
    【解决方案2】:

    检查您的机器上是否安装了 Xcode,然后在终端中运行 xcode-select --install。这应该可以解决问题并允许您运行sudo gem install rails

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-25
      • 2015-08-30
      • 2017-05-07
      • 2015-06-26
      • 1970-01-01
      • 2015-08-15
      • 2014-07-28
      • 1970-01-01
      相关资源
      最近更新 更多