search
LoginSignup
28

More than 5 years have passed since last update.

posted at

OSX yosemite(10.10)でnokogiriのインストールに失敗

またしてもnokogiriのインストールに失敗しました。おのれnokogiri。

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

    /Users/hoge/.rbenv/versions/2.1.5/bin/ruby extconf.rb --use-system-libraries=true
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/val00300/.rbenv/versions/2.1.5/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=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --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-pkg-config
    --without-pkg-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-pkg-config
    --without-pkg-config

extconf failed, exit code 1

Gem files will remain installed in 
/workspace/.bundle/gems/ruby/2.1.0/gems/nokogiri-1.6.2.1 for inspection.
Results logged to 
/workspace/.bundle/gems/ruby/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/nokogiri-1.6.2.1/gem_make.out
An error occurred while installing nokogiri (1.6.2.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.2.1'` succeeds before bundling.

以下のコマンドを試したのですがうまくいきませんでした。
bundle configのオプションもいろいろ組み替えてうまくいかず...。

brew install libxml2 libxslt libiconv
brew link --force libxml2 libxslt libiconv
bundle config build.nokogiri --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xslt-config=/usr/local/opt/libxslt/bin/xslt-config --with-iconv-lib=/usr/local/opt/libiconv/lib --with-iconv-include=/usr/local/opt/libiconv/include --with-xml2-include=/usr/local/opt/libxml2/include --use-system-libraries=true

最終的に ここ にたどり着き、

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

で解決。
理由はよくわかりませんが、HomeBrewで入れたlibxmll2ではなく、Xcodeの方のlibxml2を使わないとだめってことですね。

参考URL

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
28