therubyracer、libv8、bundle install問題

僕の場合、`libv8`のインストールは失敗しなかったのですが、 `therubyracer`で詰まりました。
同じような現象が起きてる人のものを参考にしたのですが、全くうまくいかず。。。
調査内容をまとめていきます。
※アプリ名やディレクトリ名は適宜変えて、記載しています。

## 参考サイト
##### Rails で therubyracer をインストールしているのに bundle install が通らない時の対処
http://qiita.com/takecian/items/4e7504f6b5987d1621ae

##### libv8 の gem install にハマって解決したメモ
http://qiita.com/south37/items/9a3269c28d9fba80f0b7

##### OS X El Capitanでlibv8 / therubyracerのbundle installに失敗する問題の解決方法
http://qiita.com/ganta/items/53f616b48e94d989952f

##### gccとかlibv8とかtherubyracerとかのinstallでハマった
http://wknar.hatenablog.com/entry/update-gcc-and-v8

## 動作環境

* OSX
* Rails 4.1.4
* Ruby 2.1.4



## therubyracerで失敗する
`bundle install`した際にまずつまりました。

```
$ bundle install --path vendor/bundle
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies....
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.2
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using rack 1.5.5
Using mime-types 1.25.1
Using polyglot 0.3.5
Using arel 5.0.1.20140414130214
Using thor 0.19.1
Using aws_cf_signer 0.1.3
Using ice_nine 0.11.1
Using coderay 1.1.0
Using debug_inspector 0.0.2
Using uniform_notifier 1.9.0
Using bundler 1.14.6
Using columnize 0.9.0
Using choice 0.2.0
Using unf_ext 0.0.7.1
Using netrc 0.11.0
Using coffee-script-source 1.9.1.1
Using execjs 2.6.0
Using multipart-post 2.0.0
Using diff-lcs 1.2.5
Using dotenv 2.0.2
Using equalizer 0.0.11
Using ffi 1.9.10
Using formatador 0.2.5
Using git-version-bump 0.15.1
Using hashie 3.4.3
Using multi_json 1.11.2
Using multi_xml 0.5.5
Using tilt 1.4.1
Using rb-fsevent 0.9.6
Using lumberjack 1.0.9
Using nenv 0.2.0
Using shellany 0.0.1
Using method_source 0.8.2
Using slop 3.6.0
Using guard-compat 1.2.1
Using rspec-support 3.3.0
Using hike 1.2.3
Using hirb 0.7.3
Using unicode-display_width 0.1.1
Using jpmobile 4.2.0
Using libv8 3.16.14.13
Using newrelic_rpm 3.14.0.305
Using pg 0.18.3
Using yard 0.8.7.6
Using ruby-graphviz 1.2.2
Using rails_serve_static_assets 0.0.4
Using rails_stdout_logging 0.0.4
Using ref 2.0.0
Using sass 3.2.19
Using settingslogic 2.0.9
Using spring 1.4.0
Using sqlite3 1.3.11
Using timecop 0.8.0
Using wkhtmltopdf-binary 0.9.9.3
Using rdoc 4.2.0
Using tzinfo 1.2.2
Using descendants_tracker 0.0.4
Using rack-test 0.6.3
Using rack-accept 0.4.5
Using rack-mount 0.8.3
Using passenger 5.0.21
Using treetop 1.4.15
Using tapp 1.5.0
Using better_errors 2.1.1
Using binding_of_caller 0.7.2
Using byebug 5.0.0
Using unf 0.1.4
Using coffee-script 2.4.1
Using uglifier 2.7.2
Using rb-inotify 0.9.5
Using rack-contrib 1.4.0
Using notiffany 0.0.8
Using pry 0.10.3
Using rspec-core 3.3.2
Using rspec-expectations 3.3.1
Using rspec-mocks 3.3.2
Using sprockets 2.12.4
Using hirb-unicode 0.0.5
Using rails_12factor 0.0.3
Installing therubyracer 0.12.2 with native extensions
Using sdoc 0.4.1
Using activesupport 4.1.4
Using axiom-types 0.1.1
Using coercible 1.0.0
Using mail 2.5.4
Using domain_name 0.5.25
Using listen 3.0.3
Using pry-byebug 3.2.0
Using pry-doc 0.8.0
Using pry-rails 0.3.4
Using rspec 3.3.0
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/home/.rbenv/versions/2.1.4/bin/ruby extconf.rb --with-v8-dir=/usr/local/opt/v8-315/
checking for main() in -lpthread... yes
checking for main() in -lobjc... yes
checking for v8.h... no
*** 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/home/.rbenv/versions/2.1.4/bin/ruby
	--with-pthreadlib
	--without-pthreadlib
	--with-objclib
	--without-objclib
	--enable-debug
	--disable-debug
	--with-v8-dir
	--with-v8-include
	--without-v8-include=${v8-dir}/include
	--with-v8-lib
	--without-v8-lib=${v8-dir}/lib
/Users/home/project/vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.13/ext/libv8/location.rb:50:in `configure': You have chosen to use the version of V8
found on your system (Libv8::Location::System::NotFoundError)
and *not* the one that is bundle with the libv8 rubygem. However,
it could not be located. please make sure you have a version of
v8 that is compatible with 3.16.14.13 installed. You may
need to special --with-v8-dir options if it is in a non-standard
location

thanks,
The Mgmt

	from /Users/home/project/vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.13/lib/libv8.rb:7:in `configure_makefile'
	from extconf.rb:32:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/home/project/vendor/bundle/ruby/2.1.0/gems/therubyracer-0.12.2 for inspection.
Results logged to /Users/home/project/vendor/bundle/ruby/2.1.0/extensions/x86_64-darwin-15/2.1.0-static/therubyracer-0.12.2/gem_make.out

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

よく見てみると `v8.h`が無いと。
なので、まずログを確認してみました。ログは`mkmf.log`これです。

```
$ mdfind mkmf.log | grep therubyracer

# 該当ファイルを確認
$ vi /Users/home/project/vendor/bundle/ruby/2.1.0/extensions/x86_64-darwin-15/2.1.0-static/therubyracer-0.12.2/mkmf.log
```
中を確認してみると `fatal error: 'utility' file not found v8.h`で落ちてる。。。

参考サイトをみて、一旦 `therubyracer`と`libv8`をアンインストールして、オプションをつけた `therubyracer`をインストールしてみました。一緒に`v8`と`v8-315`もアンインストールしてやってみる。

```
$ gem uninstall therubyracer libv8

$ brew uninstall v8 v8-315

$ brew install homebrew/versions/v8-315

$ gem install therubyracer -v '0.12.2' -- --with-v8-dir=/usr/local/opt/v8-315/
```

このあとに`bundle install`してみたけど、やっぱり最初と同じエラーがでる。
参考サイトの中でupdate推奨しているものがあったので、試しにやってみた。

```
$ bundle update libv8
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.2
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using rack 1.5.5
Using mime-types 1.25.1
Using polyglot 0.3.5
Using arel 5.0.1.20140414130214
Using thor 0.19.1
Using aws_cf_signer 0.1.3
Using ice_nine 0.11.1
Using coderay 1.1.0
Using debug_inspector 0.0.2
Using uniform_notifier 1.9.0
Using bundler 1.14.6
Using columnize 0.9.0
Using choice 0.2.0
Using unf_ext 0.0.7.1
Using netrc 0.11.0
Using coffee-script-source 1.9.1.1
Using execjs 2.6.0
Using multipart-post 2.0.0
Using diff-lcs 1.2.5
Using dotenv 2.0.2
Using equalizer 0.0.11
Using ffi 1.9.10
Using formatador 0.2.5
Using git-version-bump 0.15.1
Using hashie 3.4.3
Using multi_json 1.11.2
Using multi_xml 0.5.5
Using tilt 1.4.1
Using rb-fsevent 0.9.6
Using lumberjack 1.0.9
Using nenv 0.2.0
Using shellany 0.0.1
Using method_source 0.8.2
Using slop 3.6.0
Using guard-compat 1.2.1
Using rspec-support 3.3.0
Using hike 1.2.3
Using hirb 0.7.3
Using unicode-display_width 0.1.1
Using jpmobile 4.2.0
Installing libv8 3.16.14.19 (x86_64-darwin-15) (was 3.16.14.13)
Using newrelic_rpm 3.14.0.305
Using pg 0.18.3
Using yard 0.8.7.6
Using ruby-graphviz 1.2.2
Using rails_serve_static_assets 0.0.4
Using rails_stdout_logging 0.0.4
Using ref 2.0.0
Using sass 3.2.19
Using settingslogic 2.0.9
Using spring 1.4.0
Using sqlite3 1.3.11
Using timecop 0.8.0
Using wkhtmltopdf-binary 0.9.9.3
Using rdoc 4.2.0
Using tzinfo 1.2.2
Using descendants_tracker 0.0.4
Using rack-test 0.6.3
Using rack-accept 0.4.5
Using rack-mount 0.8.3
Using passenger 5.0.21
Using treetop 1.4.15
Using tapp 1.5.0
Using better_errors 2.1.1
Using binding_of_caller 0.7.2
Using byebug 5.0.0
Using unf 0.1.4
Using coffee-script 2.4.1
Using uglifier 2.7.2
Using rb-inotify 0.9.5
Using rack-contrib 1.4.0
Using notiffany 0.0.8
Using pry 0.10.3
Using rspec-core 3.3.2
Using rspec-expectations 3.3.1
Using rspec-mocks 3.3.2
Using sprockets 2.12.4
Using hirb-unicode 0.0.5
Using rails_12factor 0.0.3
Installing therubyracer 0.12.2 with native extensions
Using sdoc 0.4.1
Using activesupport 4.1.4
Using axiom-types 0.1.1
Using coercible 1.0.0
Using mail 2.5.4
Using domain_name 0.5.25
Using listen 3.0.3
Using pry-byebug 3.2.0
Using pry-doc 0.8.0
Using pry-rails 0.3.4
Using rspec 3.3.0
Installing actionview 4.1.4
Installing activemodel 4.1.4
Installing bullet 4.14.10
Installing databasedotcom 1.3.3
Installing factory_girl 4.5.0
Installing jbuilder 2.3.2
Installing virtus 1.0.5
Installing http-cookie 1.0.2
Installing guard 2.13.0
Installing actionpack 4.1.4
Installing activerecord 4.1.4
Installing carrierwave 0.10.0
Installing tilt-jbuilder 0.7.0
Installing grape 0.13.0
Installing rest-client 1.8.0
Installing guard-rspec 4.6.4
Installing actionmailer 4.1.4
Installing railties 4.1.4
Installing sprockets-rails 2.3.3
Installing rails-erd 1.4.4
Installing grape-jbuilder 0.2.0
Installing cloudinary 1.1.0
Installing activerecord-session_store 0.1.1
Installing coffee-rails 4.0.1
Installing dotenv-rails 2.0.2
Installing factory_girl_rails 4.5.0
Installing jquery-rails 3.1.4
Installing rspec-rails 3.3.3
Installing rails 4.1.4
Installing sass-rails 4.0.5
Installing wicked_pdf 0.11.0
Bundle updated!
```

アップデートがうまくいったので、 `bundle install`してみるとうまくいった。
`therubyracer`も`libv8`もインストール自体はうまくいっていたので、あとはupdateだけだったのかと。。。

うまくいかない方は是非ともgem指定の`bundle update`を試してみてください。