追記: エラー・メッセージにありますが、 xcode-select --install
をまずして下さい。
Rails - How to `bundle' install or update with capybara include nokogiri - Qiita を書いてから、そろそろ1年が過ぎんとしています。
OSX は 10.11 に。Xcode は 7.1 となりました。
ゆえあって gem を全削除 し、rails を再インストールしたのですが nokogiri でコケる……。
% gem install nokogiri
Fetching: nokogiri-1.6.6.2.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/Users/maangie/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20151028-14204-174wj7o.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.
-----
The file "/usr/include/iconv.h" is missing in your build environment,
which means you haven't installed Xcode Command Line Tools properly.
To install Command Line Tools, try running `xcode-select --install` on
terminal and follow the instructions. If it fails, open Xcode.app,
select from the menu "Xcode" - "Open Developer Tool" - "More Developer
Tools" to open the developer site, download the installer for your OS
version and run it.
-----
*** 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/maangie/.rvm/rubies/ruby-2.2.1/bin/$(RUBY_BASE_NAME)
--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
extconf failed, exit code 1
Gem files will remain installed in /Users/maangie/.rvm/gems/ruby-2.2.1/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /Users/maangie/.rvm/gems/ruby-2.2.1/extensions/x86_64-darwin-14/2.2.0-static/nokogiri-1.6.6.2/gem_make.out
オッケー、 NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri
さっ。
……でもコケるorz
色々調べて、以下のコマンドでインストールできました。
注: 以下のコマンドは find
と fgrep
でチートをしています。現在 (2017-02-01) では通じないようです。コメント欄の @jnchito 様のご意見を参照してください。
% XML2_INCLUDE=`find /Applications/Xcode.app -name libxml2 | fgrep '/MacOSX10'`
% gem install nokogiri -- --use-system-libraries \
--with-xml2-include=$XML2_INCLUDE
HomeBrew の libxml2 はあってもなくても同じなので、削除しちゃいました。
% brew remove libxml2
参考にさせて頂いた記事:
追記
xcrun --show-sdk-path
を使えば、もっとエレガントになるような気がします。
c.f. MacOSとHomebrewとpyenvで快適python環境を。 - Qiita