26
25

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.

Ubuntu14.04にNokogiriを導入する

Posted at

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

として完了。

まとめ

  1. sudo add-apt-repository -y ppa:brightbox/ruby-ng
  2. sudo apt-get update
  3. sudo apt-get -y install ruby2.1 ruby2.1-dev zlib1g-dev
  4. sudo gem install nokogiri
26
25
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
26
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?