9
9

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.

Rubyにnokogiriをinstallする。

Posted at

nokogiriを使ってrubyでwebページのスクレイピングをしたい。nokogiriの依存ライブラリを入れて、gem installする。

$ brew install libxml2 libxslt
$ brew link libxml2 libxslt
$ gem install 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.
-----

なんかエラーが出る。下記を参考にして、brew installしてみる。
osx - Why does installing nokogiri on Mac OS fail with libiconv is missing? - Stack Overflow

$ brew update
$ brew install libiconv
Error: No available formula for libiconv
Apple distributes libiconv with OS X, you can find it in /usr/lib.
Some build scripts fail to detect it correctly, please check existing
formulae for solutions.

なんかまだエラーでる。下記にちょうど良い感じの記事が有ったので、binaryから入れる。

■OSXでnokogiriのインストールするとき。 - めもちょう。

Nokogiri

$ 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
$ brew link libiconv

で、公式ドキュメントのを参考にしてinstall コマンドしてもエラーが出たので、上のブログを参考にして下記でinstallする。

gem install 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
9
9
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
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?