在OS X 10.9+上安装libv8 gem

我正在尝试安装libv8 3.16.14.3,但在使用最新的stable rvm和ruby-1.9.3-p125的OSX Mavericks上出现错误。

这是运行命令“gem install libv8”的输出:

~/src(branch:master) » gem install libv8 Fetching: libv8-3.16.14.3.gem (100%) Building native extensions. This could take a while... ERROR: Error installing therubyracer: ERROR: Failed to build gem native extension. /Users/me/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb creating Makefile Compiling v8 for x64 Using python 2.7.5 Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Unable to find a compiler officially supported by v8. It is recommended to use GCC v4.4 or higher Using compiler: g++ Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Unable to find a compiler officially supported by v8. It is recommended to use GCC v4.4 or higher libtool: unrecognized option `-static' libtool: Try `libtool --help' for more information. make[1]: *** [/Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/libpreparser_lib.a] Error 1 make: *** [x64.release] Error 2 /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/location.rb:36:in `block in verify_installation!': libv8 did not install properly, expected binary v8 archive '/Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a'to exist, but it was not found (Libv8::Location::Vendor::ArchiveNotFound) from /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/location.rb:35:in `each' from /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/location.rb:35:in `verify_installation!' from /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/location.rb:26:in `install!' from extconf.rb:7:in `<main>' GYP_GENERATORS=make \ build/gyp/gyp --generator-output="out" build/all.gyp \ -Ibuild/standalone.gypi --depth=. \ -Dv8_target_arch=x64 \ -S.x64 -Dv8_enable_backtrace=1 -Dv8_can_use_vfp2_instructions=true -Darm_fpu=vfpv2 -Dv8_can_use_vfp3_instructions=true -Darm_fpu=vfpv3 CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/atomicops_internals_x86_gcc.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/bignum.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/bignum-dtoa.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/cached-powers.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/conversions.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/diy-fp.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/dtoa.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/fast-dtoa.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/fixed-dtoa.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/once.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/preparse-data.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/preparser.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/preparser-api.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/scanner.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/strtod.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/token.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/unicode.o CXX(target) /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/utils.o LIBTOOL-STATIC /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/libpreparser_lib.a Gem files will remain installed in /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3 for inspection. Results logged to /Users/me/.rvm/gems/ruby-1.9.3-p125@proj-rails3-ruby19/gems/libv8-3.16.14.3/ext/libv8/gem_make.out 

这是因为OS X 10.9+正在使用GCC的4.8版本。 这在拉取请求( https://github.com/cowboyd/libv8/pull/95 )中提到的旧版本的libv8中并不正式支持。 请尝试在您的Gemfile中使用libv8的版本(或者) bundle update就足够了。 希望这可以帮助。

从libv8 自述文件

带上你自己的V8

因为libv8是therubyracer使用的V8引擎的接口,所以即使已经安装了V8,也可能需要使用libv8。 如果您希望使用自己的V8安装,而不是为您自己构build,请使用–with-system-v8选项。

使用RubyGems:

gem install libv8 [-v YOUR_VERSION] – –with-system-v8

使用Bundler(在您的Gemfile中):

bundle config build.libv8 –with-system-v8

请注意,如果您打算运行自己的V8,则必须同时安装V8及其头文件(可在Debian发行版的libv8-dev中find)。

带上你自己的编译器

您可以通过在编译之前设置CXX环境变​​量,或者将–with-cxx =选项添加到软件包configuration来指定您select的编译器:

bundle config build.libv8 –with-cxx = clang ++

编辑:

如果therubyracer引发了这个问题,请按照rider_on_rails的build议尝试以下操作 :

gem卸载libv8

gem install therubyracer -v YOUR_RUBY_RACER_VERSION

gem install libv8 -v YOUR_VERSION – –with-system-v8

你实际上可以在小牛上安装这个版本:

 gem install libv8 -v 3.11.8.17 -- --with-system-v8 

我可以证实这与rbenv和ruby1.9.3p448

El Capitan为我解决的问题:

 $ brew install v8 $ gem install libv8 -v REQUIRED_LIBV8_VERSION -- --with-system-v8 

REQUIRED_LIBV8_VERSION对于我来说是3.16.14.7 ,但是你需要检查你的包中需要哪个(这是rails 4.2.5

您可能还需要以超级用户身份运行上述命令(如果您的gem和系统库是全局的)

当我尝试接受的答案时,libv8会成功gem install libv8 ,但是bundle install会在libv8上失败。 我认为bundle install试图安装不同版本的libv8。 我能find一个适合我的解决scheme。

我需要libv8,因为therubyracer依赖于它。 为了安装它,我注意到没有安装在gem_make.out日志中的版本。 ( gem_make.out日志的path将在失败消息中。)在我的情况下,它是3.16.14.7。 (这个版本可能会随着时间而改变,以防你从现在开始阅读这三年。)然后我做了这个:

gem install libv8 -v 3.16.14.7 -- --with-v8-lib < – 从接受的答案中注意不同的标志

这允许这个工作:

gem install therubyracer

这使我可以完成我的bundle install

这在OSX优胜美地为我工作。

https://github.com/cowboyd/therubyracer/issues/339

jasonlynes在该链接上find的解决scheme对我来说是个诀窍。 别的什么都行不通。

 brew install homebrew/versions/v8-315 brew link --overwrite v8-315 --force gem install libv8 -v '3.16.14.13' -- --with-system-v8 gem install therubyracer -v '0.12.2' -- --with-system-v8 

试试我在这个问题中总结的内容: “gem install therubyracer -v'0.10.2'”on osx mavericks not installed

它为我工作(OS X小牛)

从OSX Mountain Lion升级到OSX Mavericks时,我遇到了同样的问题。 接受的答案适用于libv8,但不是当我去捆绑安装therubyracergem。

从ruby-1.8.7-p354升级到ruby-1.8.7-375对我来说是个诡计。 libv8(3.16.14.3-x86_64-darwin-13)和therubyracer(0.12.0)gem安装没有问题。

假设你使用rbenv:

 rbenv versions system * 1.8.7-p354 2.0.0-rc2 rbenv uninstall 1.8.7-p354 rbenv install 1.8.7-p375 rbenv versions system * 1.8.7-p375 2.0.0-rc2 bundle install 

这对我来说很好:

尝试安装这个预编译的gem:

https://dl.dropboxusercontent.com/u/7919548/gems/libv8/libv8-3.11.8.17-x86_64-darwin-13.gem(sha1:5ce07aaf4085fff5a5e10fe018fd6b22021bef3b

或者,如果你喜欢build立自己的:

  git clone https://github.com/cowboyd/libv8.git cd libv8 git checkout 3.11 bundle install bundle exec rake clean build binary gem install pkg/libv8-3.11.8.17-x86_64-darwin-13.gem 

来源: https : //github.com/cowboyd/libv8/issues/107

感谢FelixBünemann的修复!

您可以尝试通过libv8 github网站上提到的方法手动编译和安装gem 。

在具有RVM环境的MAC-Yosemite和ruby-2.1.1版本中

gem install libv8 -v 3.16.14.3 -- --with-v8-lib gem install therubyracer

它在上面的命令的帮助下工作,可以证实这一点。

真正为我工作的是升级ruby2.2.0,删除Gemfile.lock和捆绑再次。

像魅力一样工作!

这是为我工作。

用你的版本replace3.16.14.7

 bundle install gem install libv8 -v '3.16.14.7' -- --with-system-v8 bundle install gem uninstall libv8 -v '3.16.14.7' -- --with-system-v8 brew install homebrew/dupes/apple-gcc42 export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 export CXX=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2 export CPP=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2 bundle install 

我在El Cap遇到了类似的问题。 这是我做的。

 brew tap homebrew/dupes brew install apple-gcc42 

接着,

 export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 export CXX=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2 export CPP=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2 

最后,

 brew uninstall v8 gem install libv8 -v 3.11.8.17 -- --with-system-v8 

我尝试了以前答案中列出的一些解决scheme,但是发现运行bundle(安装其他缺less的gems)会尝试重新编译libv8(尽pipe已经使用--with-system-v8成功安装了它)来自同一个问题。

最后,我发现删除libv8 gem,从rubygems中获取gem文件,然后用--with-system-v8标志手动安装.gem文件。

 gem uninstall libv8 gem fetch libv8 -v LIBV8_VERSION gem install libv8-LIBV_VERSION.gem -- --with-system-v8 bundle 

感谢Gaurav Agarwal的带领我走向正确的道路!

我正在使用另一个项目的testing版的Xcode,并忘记了。 切换回xcode-select 。 就像是:

 sudo xcode-select --switch /Applications/Xcode.app/ 

从Gemfile中移除:

gem'therubyracer',:平台=>:ruby