Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

またしても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

mist_dev
インフラ修行中。バンド活動をしている。こっそりバイク乗り。日本のビールが好き。 AWS / Ruby on Rails
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away