低版本 therubyracer 安装出错

gem install therubyracer -v '0.12.2' 安装出错的解决方案
更新于: 2021-12-19 12:57:29

个人总结

这个东西,主要的是与 v8有关,如果不重要的系统,可以避开安装,因为会浪费很多的时间;与 rails 相关的主要就是 style/css 相关。

因此,可以想其它办法避开

报错如下

❯ gem install therubyracer -v '0.12.2'  -- --with-system-v8
Building native extensions.  This could take a while...
ERROR:  Error installing therubyracer:
        ERROR: Failed to build gem native extension.

        /Users/alo7.aric/.rbenv/versions/1.9.3-p551/bin/ruby 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.

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/alo7.aric/.rbenv/versions/1.9.3-p551/bin/ruby
        --with-pthreadlib
        --without-pthreadlib
        --with-objclib
        --without-objclib
        --enable-debug
        --disable-debug
        --with-v8-dir
        --without-v8-dir
        --with-v8-include
        --without-v8-include=${v8-dir}/include
        --with-v8-lib
        --without-v8-lib=${v8-dir}/
/Users/alo7.aric/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/libv8-3.16.14.15/ext/libv8/location.rb:50:in `configure': By using --with-system-v8, you have chosen to use the version  (Libv8::Location::System::NotFoundError)
of V8 found on your system and *not* the one that is bundled with 
the libv8 rubygem. 

However, your system version of v8 could not be located. 

Please make sure your system version of v8 that is compatible 
with 3.16.14.15 installed. You may need to use the 
--with-v8-dir option if it is installed in a non-standard location
        from /Users/alo7.aric/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/libv8-3.16.14.15/lib/libv8.rb:7:in `configure_makefile'
        from extconf.rb:32:in `<main>'


Gem files will remain installed in /Users/alo7.aric/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/therubyracer-0.12.2 for inspection.
Results logged to /Users/alo7.aric/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/therubyracer-0.12.2/ext/v8/gem_make.out

解决办法

❯ gem install therubyracer -v '0.12.2'  -- --with-v8-dir=/usr/local/opt/v8@3.15

Building native extensions.  This could take a while...
Successfully installed therubyracer-0.12.2
1 gem installed

参考

https://gist.github.com/fernandoaleman/868b64cd60ab2d51ab24e7bf384da1ca