Rails gem therubyracer 和 libv8 的安装问题

zhujinshou · 2016年04月19日 · 最后由 rikiwong 回复于 2016年04月20日 · 5054 次阅读

在 Ruby China 中已经有人问过关于该问题了,但从这些回答中自己没有找到可以解决本问题的好方式(在 Google 上也搜索了),那位大神拯救一下小白。

安装环境是 rvm1.27.0 + ruby1.9.3 + Rails3.2.14,在项目目录下进行 bundle install 后会报下面的错误:

Installing therubyracer 0.12.1 with native extensions

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

    /Users/zhujinshou/.rvm/rubies/ruby-1.9.3-p551/bin/ruby -r ./siteconf20160419-54804-1n7e3ld.rb extconf.rb --use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2
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
    --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/zhujinshou/.rvm/rubies/ruby-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/zhujinshou/.rvm/gems/ruby-1.9.3-p551@tsinova_web/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/zhujinshou/.rvm/gems/ruby-1.9.3-p551@tsinova_web/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/zhujinshou/.rvm/gems/ruby-1.9.3-p551@tsinova_web/gems/therubyracer-0.12.1 for inspection.
Results logged to /Users/zhujinshou/.rvm/gems/ruby-1.9.3-p551@tsinova_web/extensions/x86_64-darwin-15/1.9.1/therubyracer-0.12.1/gem_make.out

错误就像上面那样:Failed to build gem native extension. 网上给的装上 libv8 的方法是加上 -- --with-system-v8 但是这明显指标不治本 求助呀,江湖告急,请高手支援!

楼主你可能需要升级一些 gem 版本,用的 libv8 太旧,系统里的也不匹配

我觉得如果可以接受的话,不如在机器上装个 nodejs,然后去掉 therubyracer

如果只是为了解决 assets precompile 的话...干净整洁,也不用编译这么大的一个 V8

@killyfreedom ,这是接过来的别人的项目。在进行 gem 安装的时候就是这个安不上了,大牛给点提示?

#4 楼 @zhujinshou 用 Vagrant 开个和部署环境一样的虚拟机做开发。

@zhujinshou 最好的办法:移除 therubyracer,装一个 nodejs 即可。therubyracer 有严重的内存泄漏问题,不推荐使用(尤其是生产环境) 否则就是装上 libv8-dev,你是找不到 v8.h,根据 Debian 的包管理约定,装上 libv8-dev 就可以了。

谢谢大家,该问题已经解决了,我的解决方案是下面:

gem uninstall -a libv8
gem uninstall -a therubyracer

brew tap homebrew/dupes
brew install apple-gcc42

gem install libv8 -v '3.16.14.7' -- --with-cxx=/usr/local/bin/g++-4.2
gem install therubyracer -v '0.12.1'

参考地址是:https://github.com/cowboyd/libv8/issues/205

需要 登录 后方可回复, 如果你还没有账号请 注册新账号