[Ruby] bundle install で nokogiri のインストール中に “libiconv is missing” エラー発生


bundle install で nokogiri のインストール中に “libiconv is missing” という、libiconv が見つからないエラーが発生しました。

エラー内容

$ bundle install --no-deploymentFetching source index for https://rubygems.org/
...
 
Installing nokogiri (1.5.2) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
 
        /Users/bakorer/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb 
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
-----
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
	--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/bakorer/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
	--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-iconv-dir
	--without-iconv-dir
	--with-iconv-include
	--without-iconv-include=${iconv-dir}/include
	--with-iconv-lib
	--without-iconv-lib=${iconv-dir}/lib
	--with-xml2-dir
	--without-xml2-dir
	--with-xml2-include
	--without-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-iconvlib
	--without-iconvlib
 
 
Gem files will remain installed in /Users/bakorer/.rvm/gems/ruby-1.9.2-p290@tomcms/gems/nokogiri-1.5.2 for inspection.
Results logged to /Users/bakorer/.rvm/gems/ruby-1.9.2-p290@tomcms/gems/nokogiri-1.5.2/ext/nokogiri/gem_make.out
An error occured while installing nokogiri (1.5.2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.5.2'` succeeds before bundling.

解決方法

以下のコマンドを Railsアプリのルートディレクトリで実行して、bundler に nokogiri をコンパイルするとき使う libiconv などを指定してやればOKです。

$ bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib  --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26  --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include  --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib

以上です。


参考情報

Mac | CreativeStyle

[Ruby] Nokogiri のインストール方法 [Mac版] | CodeNote.net

  1. コメントはまだありません。

  1. トラックバックはまだありません。