Help us understand the problem. What is going on with this article?

bundler でnokogiriがインストールできなかった件の対応 実はbrew側の問題だった

More than 3 years have passed since last update.

3行で事情を説明

  • 年末年始休暇の間で、プライベートのmacでbundle install を試し成功
  • 職場で使っているmacで同様にやろうとしたら、nokogiriのインストールでつまづく
  • この環境下では、ライブラリをbrew link してなかったことが原因だった

なお、プライベートのmac、職場のmacのOSはどちらも EL Capitan。

エラー発生

Railsプロジェクトに対し、bundleでプロジェクト用のgemをインストールしようとした時に、なにやらエラーが。

terminal
$ bundle install --path vendor/bundle

(前略)
Installing nokogiri 1.6.7.1 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/rojiuratech/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20160105-45677-tur1ij.rb extconf.rb --use-system-libraries
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** 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.

(中略)

An error occurred while installing nokogiri (1.6.7.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.7.1'` succeeds before bundling.

ここのエラーログを見ると、libxml2のバージョン2.6.21以上が必要とのことだが、実際には

terminal
$ brew info libxml2 
libxml2: stable 2.9.2 (bottled), HEAD [keg-only]

バージョンが古いわけではない。

brew link が必要だった

シンボリックリンクがなかったようだ?!
これ、プライベートのmacbookでやったかな?やってなかったような。

terminal
$ brew link --force libxml2
Linking /usr/local/Cellar/libxml2/2.9.2... 82 symlinks created

$ brew link --force libxslt
Linking /usr/local/Cellar/libxslt/1.1.28_1... 22 symlinks created

再度試す 今度はOK

terminal
$ bundle install --path vendor/bundle
Using activerecord 4.2.5
Installing nokogiri 1.6.7.1 with native extensions
Installing rails-dom-testing 1.0.7
(中略)
Installing rails 4.2.5
Bundle complete! 1 Gemfile dependency, 34 gems now installed.
Bundled gems are installed into ./vendor/bundle.

今度はうまくいった。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away