Posted at

Mac OS X Mavericks で bundle install した時 nokogiri が "libiconv is missing."でインストールできなかった

More than 5 years have passed since last update.


railsチュートリアルをやっておりましたところ、bundle install で nokogiri というgemがインストール出来ない問題に出くわしました。

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/Users/niwatako/.rbenv/versions/2.0.0-p481/bin/ruby extconf.rb --with-xml2-include=/usr/local/opt/libxml2/include/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xslt-dir=/usr/local/opt/libxslt
Building nokogiri using packaged libraries.
libiconv is missing. please visit for help with installing dependencies.
*** 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:

Gem files will remain installed in /Users/niwatako/project/rails/4.0.5/sample_app/vendor/bundle/gems/nokogiri- for inspection.
Results logged to /Users/niwatako/project/rails/4.0.5/sample_app/vendor/bundle/gems/nokogiri-
An error occurred while installing nokogiri (, and Bundler cannot
Make sure that `gem install nokogiri -v ''` succeeds before bundling.


source ''

ruby '2.0.0'

gem 'rails', '4.0.5'

group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
gem 'guard-rspec', '2.5.0'
gem 'spork-rails', '4.0.0'
gem 'guard-spork', '1.5.0'
gem 'childprocess', '0.3.6'

group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'

# Uncomment this line on OS X.
# gem 'growl', '1.0.3'

# Uncomment these lines on Linux.
# gem 'libnotify', '0.8.0'

# Uncomment these lines on Windows.
# gem 'rb-notifu', '0.0.4'
# gem 'win32console', '1.3.2'

gem 'sass-rails', '4.0.2'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
gem 'sdoc', '0.3.20', require: false

group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'


これを解決するには libiconv を homebrew で入れてやって、bundler に nokogiri 用のビルド設定をしてやります。

# homebrew公式に libiconv が無いので libiconv formula を追加

brew tap homebrew/dupes

# libxml2、libxslt、libiconv のインストール
brew install libxml2 libxslt libiconv
brew link --force libxml2 libxslt libiconv

# nokogiri 用のビルド設定をbundlerにいれてやる
bundle config build.nokogiri --use-system-libraries

# 無事インストールできるはず
bundle install

ちなみにbundle config build.nokogiri --use-system-librariesの設定がどこに保存されるかというと、~/.bundle/configに保存されています。


BUNDLE_BUILD__NOKOGIRI: --use-system-libraries