諸行無常

IT色々お勉強中のブログ

bundle install で gem install nokogiriで失敗する

久しぶりにrailsアプリを作ろうとしたらnokogiriエラー いつも直し方を忘れるのでメモ

エラー↓

-[2197]% bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies...
Installing rake 11.3.0
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.9.0
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Installing mini_portile2 2.1.0
Installing pkg-config 1.1.7
Using rack 1.6.4
Using mime-types-data 3.2016.0521
Using arel 6.0.3
Using bundler 1.13.1
Using concurrent-ruby 1.0.2
Using pg 0.18.4
Using thor 0.19.1
Using tzinfo 1.2.2
Installing nokogiri 1.6.8 with native extensions
Using rack-test 0.6.3
Using mime-types 3.1
Installing sprockets 3.7.0
Installing activesupport 4.2.7
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/hoge/.rbenv/versions/2.2.4/bin/ruby -r ./siteconf20160922-5722-8tk2uq.rb extconf.rb
Using pkg-config version 1.1.7
checking if the C compiler accepts ... *** 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=/Users/hoge/.rbenv/versions/2.2.4/bin/$(RUBY_BASE_NAME)
  --help
  --clean
/Users/hoge/.rbenv/versions/2.2.4/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
  from /Users/hoge/.rbenv/versions/2.2.4/lib/ruby/2.2.0/mkmf.rb:571:in `block in try_compile'
  from /Users/hoge/.rbenv/versions/2.2.4/lib/ruby/2.2.0/mkmf.rb:522:in `with_werror'
  from /Users/hoge/.rbenv/versions/2.2.4/lib/ruby/2.2.0/mkmf.rb:571:in `try_compile'
  from extconf.rb:138:in `nokogiri_try_compile'
  from extconf.rb:162:in `block in add_cflags'
  from /Users/hoge/.rbenv/versions/2.2.4/lib/ruby/2.2.0/mkmf.rb:619:in `with_cflags'
  from extconf.rb:161:in `add_cflags'
  from extconf.rb:414:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/hoge/.rbenv/versions/2.2.4/gemsets/mirtialart/gems/nokogiri-1.6.8 for inspection.
Results logged to /Users/hoge/.rbenv/versions/2.2.4/gemsets/mirtialart/extensions/x86_64-darwin-14/2.2.0-static/nokogiri-1.6.8/gem_make.out

An error occurred while installing nokogiri (1.6.8), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.8'` succeeds before bundling.
bundle install  4.84s user 2.01s system 42% cpu 16.259 total

以下コマンドを打ったらbundle installできるようになった。なんでだろ、、、

-[2204]% xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
-(hoge@hoge-no-MacBook-Air)-(1)-<2016/09/22 15:24>----------------------------------------------------------[/Users/hoge/rails_projects/mirtialart]-
-[2204]% bundle config build.nokogiri --use-system-libraries