Help us understand the problem. What is going on with this article?

OS X 10.9でNokogiriのインストールエラーを解決

More than 5 years have passed since last update.

かなりハマったのでメモ。どなたかの参考になれば!

環境:
OS X 10.9.4
ruby 2.0.0p451("$ ruby -v")
homebrew 0.9.5("$ brew -v")

bundle installでエラー、個別にやっても失敗

$ gem install nokogiri

以下のエラーが発生。

An error occurred while installing nokogiri (1.6.0), 
and Bundler cannot continue.Make sure that gem install 
nokogiri -v '1.6.0' succeeds before 
bundling.

Nokogiriのサイトの手順に沿ってもエラー
http://nokogiri.org/tutorials/installing_nokogiri.html)

$ brew install libxml2 libxslt
$ brew link libxml2 libxslt
$ wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
(※直接URLを叩いてtar.gzファイルをDLし、/usr/local/Cellar/libiconv/に置きました)
$ tar xvfz libiconv-1.13.1.tar.gz
$ cd libiconv-1.13.1
$ ./configure --prefix=/usr/local/Cellar/libiconv/1.13.1
$ make
$ sudo make install
$ sudo gem install nokogiri -- 
--with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib 
--with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28 
--with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include 
--with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib

以下のエラーが発生

checking for iconv_open() in iconv.h... yes
checking for iconv_open() in -liconv... no
checking for iconv_open() in -liconv... no
checking for libiconv_open() in iconv.h... no
checking for libiconv_open() in -liconv... no
checking for libiconv_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 necessarylibraries and/or headers.  Check the mkmf.log file for more details.  You mayneed configuration options.

iconv.hは認識されてるけど、iconv_open()でエラー!?mkmf.logを見たりしつつ、わわからないなりに色々と調べてみたが、とりあえずはこちらのコマンドで解決。
XcodeのCommand Line Toolsがインストールされてませんでした。。
単純なミスだけどなかなか気付けず、ハマってしまいました。

$ xcode-select --install

その後、先ほどのコマンドでNokogiriのインストールできました。

$ sudo gem install nokogiri -- 
--with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib 
--with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28 
--with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include 
--with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib
keitaj
http://ja.stackoverflow.com/users/8558/suzuki-keita
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした