rubyを導入する
sudo add-apt-repository -y ppa:brightbox/ruby-ng
sudo apt-get update
sudo apt-get -y install ruby2.1
この状態で
sudo gem install nokogiri
すると、下記のエラーが出る。
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/usr/bin/ruby2.1 extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
よって、解決するために
コンパイルに必要な環境を整える
sudo apt-get install ruby2.1-dev
この状態で
sudo gem install nokogiri
すると、下記のエラーが出る。
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/usr/bin/ruby2.1 extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
*** 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
--curdir
--ruby=/usr/bin/ruby2.1
--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
extconf failed, exit code 1
よって、解決するために
sudo apt-get install zlib1g-dev
とすればよい。最後に
Nokogiriを導入する
sudo gem install nokogiri
として完了。
まとめ
- sudo add-apt-repository -y ppa:brightbox/ruby-ng
- sudo apt-get update
- sudo apt-get -y install ruby2.1 ruby2.1-dev zlib1g-dev
- sudo gem install nokogiri