Ruby
bundler
macos
therubyracer
libv8

macOS で bundle install 時に libv8, therubyracer インストールに失敗するときの解決法

条件

macOS High Sierra
vendor/bundle 内にgemをインストールする設定

症状

v8が見つからずインストール出来ない

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

    /Users/misogi/.rbenv/versions/2.2.8/bin/ruby -r ./siteconf20171215-25681-1he2s37.rb extconf.rb --with-system-v8
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.

解決

以下を実行し、bundle config を変更する

$ bundle config --local build.therubyracer --with-v8-include=/Users/misogi/vagrant/linus-vagrant/linus/vendor/bundle/ruby/2.2.0/gems/libv8-3.16.14.7/vendor/v8/include
$ bundle config --local build.libv8 --with-system-v8
.bundle/config
BUNDLE_BUILD__LIBV8: "--with-system-v8"
BUNDLE_BUILD__THERUBYRACER: "--with-v8-include=/Users/misogi/vagrant/linus-vagrant/linus/vendor/bundle/ruby/2.2.0/gems/libv8-3.16.14.7/vendor/v8/include"

参考

http://wknar.hatenablog.com/entry/update-gcc-and-v8
https://qiita.com/wapa5pow/items/1b7447df6a6ee75f8899
https://qiita.com/ganta/items/53f616b48e94d989952f