82
78

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

##問題
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 http://nokogiri.org/tutorials/installing_nokogiri.html 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:
	--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/niwatako/.rbenv/versions/2.0.0-p481/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


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

この時のGemfile

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_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'
end

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'
end

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
end

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

解決

これを解決するには 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
82
78
1

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
  3. You can use dark theme
What you can do with signing up
82
78

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?