ponkiti's blog

主に自分用、イベント参加メモや備忘録として利用

nokogiriがインストールできずにbundle installできない

Ruby on Rails チュートリアル第3章の初っ端からbundle installができず、つまってしまった。

エラー内容

[vagrant@localhost sample_app]$ bundle install --without production
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using rake 10.3.2
(省略)
Using bundler 1.7.4
Installing mini_portile 0.6.0
Building nokogiri using packaged libraries.
Building libxml2-2.8.0 for nokogiri with the following patches applied:
     - 0001-Fix-parser-local-buffers-size-problems.patch
     - 0002-Fix-entities-local-buffers-size-problems.patch
     - 0003-Fix-an-error-in-previous-commit.patch
     - 0004-Fix-potential-out-of-bound-access.patch
     - 0005-Detect-excessive-entities-expansion-upon-replacement.patch
     - 0006-Do-not-fetch-external-parsed-entities.patch
     - 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
     - 0008-Improve-handling-of-xmlStopParser.patch
     - 0009-Fix-a-couple-of-return-without-value.patch
     - 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
     - 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT!  Nokogiri builds and uses a packaged version of libxml2.

If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:

    gem install nokogiri -- --use-system-libraries

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install

However, note that nokogiri does not necessarily support all versions
of libxml2.

For example, libxml2-2.9.0 and higher are currently known to be broken
and thus unsupported by nokogiri, due to compatibility problems and
XPath optimization bugs.
************************************************************************

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /home/vagrant/.rbenv/versions/2.0.0-p0/bin/ruby extconf.rb
Building nokogiri using packaged libraries.
checking for iconv.h... yes
checking for iconv_open() in iconv.h... yes
Building libxml2-2.8.0 for nokogiri with the following patches applied:
     - 0001-Fix-parser-local-buffers-size-problems.patch
     - 0002-Fix-entities-local-buffers-size-problems.patch
     - 0003-Fix-an-error-in-previous-commit.patch
     - 0004-Fix-potential-out-of-bound-access.patch
     - 0005-Detect-excessive-entities-expansion-upon-replacement.patch
     - 0006-Do-not-fetch-external-parsed-entities.patch
     - 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
     - 0008-Improve-handling-of-xmlStopParser.patch
     - 0009-Fix-a-couple-of-return-without-value.patch
     - 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
     - 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT!  Nokogiri builds and uses a packaged version of libxml2.

If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:

    gem install nokogiri -- --use-system-libraries

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install

However, note that nokogiri does not necessarily support all versions
of libxml2.

For example, libxml2-2.9.0 and higher are currently known to be broken
and thus unsupported by nokogiri, due to compatibility problems and
XPath optimization bugs.
************************************************************************
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0... OK
Running patch with /home/vagrant/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.3.1/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch...
Running 'patch' for libxml2 2.8.0... ERROR, review 'tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0/patch.log' to see what happened.
*** 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
     --without-make-prog
     --srcdir=.
     --curdir
     --ruby=/home/vagrant/.rbenv/versions/2.0.0-p0/bin/ruby
     --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
/home/vagrant/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/mini_portile-0.6.0/lib/mini_portile.rb:279:in `block in execute': Failed to complete patch task (RuntimeError)
     from /home/vagrant/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/mini_portile-0.6.0/lib/mini_portile.rb:271:in `chdir'
     from /home/vagrant/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/mini_portile-0.6.0/lib/mini_portile.rb:271:in `execute'
     from extconf.rb:282:in `block in patch'
     from extconf.rb:279:in `each'
     from extconf.rb:279:in `patch'
     from /home/vagrant/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/mini_portile-0.6.0/lib/mini_portile.rb:108:in `cook'
     from extconf.rb:253:in `block in process_recipe'
     from extconf.rb:154:in `tap'
     from extconf.rb:154:in `process_recipe'
     from extconf.rb:423:in `<main>'


Gem files will remain installed in /home/vagrant/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.3.1 for inspection.
Results logged to /home/vagrant/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.3.1/ext/nokogiri/gem_make.out
An error occurred while installing nokogiri (1.6.3.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.3.1'` succeeds before bundling.

パッケージをインストール

[vagrant@localhost sample_app]$ sudo yum install libxml2-devel libxslt-devel
(省略)
Complete!

nokogiriをインストール

[vagrant@localhost sample_app]$ gem install nokogiri
(省略)
Gem files will remain installed in /home/vagrant/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.3.1 for inspection.
Results logged to /home/vagrant/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.3.1/ext/nokogiri/gem_make.out

再度bundle install

[vagrant@localhost sample_app]$ bundle install --without production
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using rake 10.3.2
(省略)
Installing nokogiri 1.6.0
(省略)
Your bundle is complete!
Gems in the group production were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
Post-install message from capybara:
IMPORTANT! Some of the defaults have changed in Capybara 2.1. If you're experiencing failures,
please revert to the old behaviour by setting:

    Capybara.configure do |config|
      config.match = :one
      config.exact_options = true
      config.ignore_hidden_elements = true
      config.visible_text_only = true
    end

If you're migrating from Capybara 1.x, try:

    Capybara.configure do |config|
      config.match = :prefer_exact
      config.ignore_hidden_elements = false
    end

Details here: http://www.elabs.se/blog/60-introducing-capybara-2-1

bundle installできた!

以前も同じようなエラーが出て、その時はXcodeのcommand line developer toolsをインストールしたら解決したんだが・・・。nokogiri問題について後で調べておきたい。