40

正如您在下面看到的,libv8 可以正常安装,但 ruby​​racer 不能。我正在使用 Mac 10.7.4。

~/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1> gem install libv8
Building native extensions.  This could take a while...
Successfully installed libv8-3.11.8.3
1 gem installed
Installing ri documentation for libv8-3.11.8.3...
Installing RDoc documentation for libv8-3.11.8.3...

~/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1> gem install therubyracer
Building native extensions.  This could take a while...
ERROR:  Error installing therubyracer:
    ERROR: Failed to build gem native extension.

        /Users/rdp/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
checking for main() in -lobjc... *** 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/rdp/.rvm/rubies/ruby-1.9.3-p125/bin/ruby
    --with-objclib
    --without-objclib
/Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:461:in `try_link0'
    from /Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:476:in `try_link'
    from /Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:619:in `try_func'
    from /Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:845:in `block in have_library'
    from /Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from /Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:840:in `have_library'
    from extconf.rb:10:in `<main>'


Gem files will remain installed in /Users/rdp/.rvm/gems/ruby-1.9.3-p125/gems/therubyracer-0.10.1 for inspection.
Results logged to /Users/rdp/.rvm/gems/ruby-1.9.3-p125/gems/therubyracer-0.10.1/ext/v8/gem_make.out

mkmf.log是位于 中的~/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/gems/1.9/gems/therubyracer-0.10.1/ext/v8>

文件编辑选项缓冲区工具帮助

"/usr/bin/gcc-4.2 -o conftest -I/Users/rdp/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/x86_64-darwin11.3.0 -I/Users/rdp/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/rub\
y/backward -I/Users/rdp/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1 -I. -I/Users/rdp/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE    -O3 -ggdb -Wextra -Wno-unused-\
parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-functio\
n-declaration  -fno-common -pipe conftest.c  -L. -L/Users/rdp/.rvm/rubies/ruby-1.9.3-p125/lib -L/Users/rdp/.rvm/usr/lib -L.      -lruby.1.9.1  -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */
4

13 回答 13

88

您可以使用 brew 中的 Libv8 而不是 gem 中的 Libv8。您可以通过以下命令执行此操作:

$ gem uninstall libv8
$ brew install v8
$ gem install therubyracer
于 2012-12-29T09:23:15.627 回答
11

@Haegin 在https://github.com/cowboyd/libv8/issues/205中的回答

brew uninstall v8
brew install v8-315
gem uninstall -a libv8
gem uninstall -a therubyracer
gem install libv8 -v '3.16.14.17' -- --with-system-v8
gem install therubyracer -v '0.12.2' -- --with-v8-dir=$(brew --prefix v8-315)
于 2019-04-12T05:44:07.720 回答
10

对于一个较旧的项目,我不得不在 Mavericks 上使用 0.10.1 版本的 ruby​​racer(引导程序取决于它)

所以我不得不使用旧版本的 gcc

  1. 编辑您的 .zshrc 或 .bashrc

    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
    
  2. 确保您已卸载所有旧版本的 libv8

    gem uninstall libv8
    
  3. 安装您的 therubyracer 版本

    gem install therubyracer -v=0.10.1
    
于 2014-01-30T10:03:31.900 回答
5

对于 Linux:

下面的代码当然是正确的

$ gem uninstall libv8

$ gem install therubyracer

但有时它并没有帮助,因为你没有编程make首先你需要安装make。为此,请运行:

sudo apt-get install build-essential

只有在那之后:

gem install therubyracer

于 2017-06-29T12:57:55.247 回答
4

在 Mavericks 上,您只需要更新到 therubyracer 0.12.0

于 2014-01-21T19:43:52.080 回答
3

这些步骤对我有用:

  • brew uninstall v8
  • brew install v8-315
  • gem uninstall -a libv8
  • gem uninstall -a therubyracer
  • gem install libv8 -v '3.16.14.19' -- --with-system-v8
  • gem install therubyracer -v '0.12.3' -- --with-v8-dir=$(brew --prefix v8-315)
于 2021-01-07T16:30:16.113 回答
2

Mac 10.10.5,Ruby 2.1.0 这对我有用:

gem uninstall libv8
gem uninstall therubyracer

brew upgrade gcc
brew install v8

bundle config --local build.libv8 --with-cxx=/usr/local/bin/gcc-6
gem install libv8 -v '3.16.14.17' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315

bundle install # worked !
于 2017-02-08T15:36:57.043 回答
1

对我有用的解决方案是将这些步骤放在 10.7.4 上

export CC=gcc-4.2

sudo ln /usr/bin/gcc /usr/bin/gcc-4.2

gem uninstall libv8
gem install therubyracer
于 2012-10-01T14:08:23.823 回答
0

到目前为止,我遇到了完全相同的问题。

这个链接救了我。

总结一下,你需要这样做:

$ gem uninstall libv8
$ gem install therubyracer

在我解决这个问题之前,我在我的 mac 中安装了 v8。我不知道这是否有帮助,因为它似乎与 js 解释器有关,我认为它可能会有所帮助。

于 2012-07-22T10:05:44.833 回答
0

在 Mountain Lion 10.8 上,它没有预装 C 编译器。您需要从 Apple 自己下载并安装“命令行工具”包,然后运行which gcc以确认它已安装。从那里开始一切都应该运行良好。

于 2012-12-20T22:39:59.380 回答
0

在 OS X 10.7 上,我实际上发现“命令行工具”包是不够的,我必须安装成熟的 XCode 包,然后 gem install 工作。

于 2013-03-24T15:20:42.060 回答
0

当我从 OSX Mountain Lion 升级到 OSX Mavericks 时,我遇到了同样的问题。

从 ruby​​-1.8.7-p354 升级到 ruby​​-1.8.7-375 对我有用。如果您使用的是 ruby​​-1.93-p125,您可能想尝试升级到 1.9.3-rc1(已经高于 p484)

libv8 (3.16.14.3-x86_64-darwin-13) 和 therubyracer (0.12.0) gems 安装没有问题。

假设您使用 rbenv:

rbenv install 1.9.3-rc1
rbenv rehash
rbenv shell 1.9.3-rc1
bundle install
于 2014-04-05T03:15:00.933 回答
0

根据https://github.com/cowboyd/therubyracer/issues/420#issuecomment-253592865

gem uninstall therubyracer
gem uninstall libv8
brew uninstall v8
brew install v8
gem install libv8
gem install therubyracer

它帮助了我。参数:ruby 2.3.3,rails 4.2.9

于 2018-06-28T08:54:56.267 回答