LoginSignup
0
1

More than 5 years have passed since last update.

[Ruby] nokogiriをインストールする

Last updated at Posted at 2014-12-13

RailsでRSpecを使う勉強で、$ bundle exec rspecを実行するとnokogiriとやらが見つからないとエラーが出た。
インストールしようとしてみたら以下のエラー。

Building native extensions.  This could take a while...
Building nokogiri using packaged libraries.
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    /usr/local/Cellar/ruby/2.0.0-p247/bin/ruby extconf.rb
Building nokogiri using packaged libraries.
-----
libiconv is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----

libiconvとやらが見つからなくてnokogiriとやらのインストール中にエラーが起きたらしい。

下記の記事を参考にlibiconvからインストールを試みる。
http://qiita.com/tarr1124/items/3ef609961b3c425a75b9

# srcディレクトリがなかったので作成
$ mkdir /usr/local/src
$ cd /usr/local/src/
$ wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
$ tar xzvf libiconv-1.13.1.tar.gz 
$ cd libiconv-1.13.1
$ ./configure --prefix=/usr/local/Cellar/libiconv/1.13.1
$ make
$ make install

$ make installのところでまたしてもエラー。

/usr/local/include is not writable

/user/local/include に書き込めないと。
これあれだよね、ぱーみっしょんとかいうやつ変えるんだよね。
ということで下記を参考に
http://qiita.com/u1_fukui/items/b82704555f6cd04a4209

$ cd /usr/local/
$ sudo chmod g+w include
$ sudo chown :admin include
$ sudo chmod g+w lib
$ sudo chown :admin lib

これでlibiconvのインストールも出来た。
というわけでついにnokogiriをインストール

$ brew install libxml2 libxslt
$ brew link libxml2 libxslt --force
$ gem install nokogiri

そして$ bundle install
そしてエラー。
そして検索。

$ bundle config build.nokogiri --use-system-libraries
$ bundle install --path vendor/bundle

下記参照にしたところ、こうすればいいらしいですね。
http://qiita.com/pugiemonn/items/4b23a709ed194b02be6d

ようやくrspecコマンドが通りました。

0
1
0

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
0
1