therubyracer - Gem::Ext::BuildError: 错误:无法构建本地宝石扩展。涉及到 IT 技术。

85

我正在尝试在Mavericks上安装以下gem版本:

  • libv8 (3.16.14.3)
  • therubyracer (0.12.1)

显然,therubyracer gem依赖于libv8。

1)安装libv8

什么是libv8?我的一点研究似乎表明它是谷歌Chrome使用的某种javascript库?

我在安装时遇到了麻烦,但这篇很棒的文章解决了我的问题,并详细说明了如何绕过它。

因此我使用以下命令安装了libv8

gem install libv8 -- --with-system-v8

据我理解,这个命令会安装 gem,但是会使用我本地系统安装的 v8 库而非 gem 自带的版本?无论如何,安装成功了。

2) 安装 therubyracer

在接下来的步骤中,我遇到了安装 therubyracer gem 的问题。我不太清楚这个 gem 做什么用的,只知道它是一个 Rails 项目的依赖项,我想要通过 bundle install 安装。

它给我报了以下错误:

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

    /Users/jeeves.butler/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb 
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/jeeves.butler/.rvm/rubies/ruby-1.9.2-p290/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}/lib
/Users/jeeves.butler/.rvm/gems/ruby-1.9.2-p290/gems/libv8-3.16.14.3/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 bundled 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.3 installed. You may
need to special --with-v8-dir options if it is in a non-standard
location

thanks,
The Mgmt

    from /Users/jeeves.butler/.rvm/gems/ruby-1.9.2-p290/gems/libv8-3.16.14.3/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/jeeves.butler/.rvm/gems/ruby-1.9.2-p290/gems/therubyracer-0.12.1 for inspection.
Results logged to /Users/jeeves.butler/.rvm/gems/ruby-1.9.2-p290/extensions/x86_64-darwin-13/1.9.1/therubyracer-0.12.1/gem_make.out
根据我了解的情况,我选择使用本地V8库安装libv8而不是使用提供的libv8。但现在本地安装无法找到。
- 我要如何检查是否已安装V8并如何定位它? - 我尝试了一些指定的标志,但没有一个指向正确的安装目录。 - 这可能是一个单独的话题,但是extconf.rb是什么?我在几个地方看到过。它试图特别使用gcc编译器做什么?
谢谢!
编辑:
1. 我尝试了卸载libv8并通过brew install重新安装的此解决方法。这在几个类似的问题中也被提到。没有成功。
2. 我也尝试了环境变量CCCXXCPP,如此处所述,虽然我认为它没有任何影响,因为它已经选择了我的gcc v4.6编译器。

这个 this,也许可以吗? - dax
2
<sigh>我在Mac上安装therubyracer总是有问题=( - maerics
15个回答

167

这些步骤对我起作用了。

操作系统: Maverick Ruby版本: 2.1.1

gem uninstall libv8
gem install therubyracer -v '0.11.3'
gem install libv8 -v '3.11.8.13' -- --with-system-v8

接受这个答案,但有一个更改。我交换了步骤3和2的顺序,使其正常工作 - 先安装libv8,然后再安装theruby racer。谢谢! - user2490003
谢谢,这个方法很有效!也许是我太累了,但如果你的指示用“#”代替版本号会更有帮助。我需要安装不同的版本,但我只是复制了你的笔记。 - Taylored Web Sites
请注意,libv8版本非常重要,如此处所示(https://github.com/cowboyd/libv8/blob/master/README.md),奇数点发布版(版本中的最后两位数字)也包含二进制文件。 - Jimmy Chu
安装/卸载/重新安装在Mojave上对我起作用了。我讨厌这个老东西!:D - Petercopter

76

对于在OS X El Capitan中遇到此问题的人,这个解决方案来自于一个therubyracer问题线程,最终对我有用:

brew tap homebrew/versions
brew install v8-315

gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315

bundle install

我之前也运行过brew install gcc,但我不确定这是否真的是必要的。


1
我最终让它工作了,但在此之前我不得不删除我的Gemfile.lock。谢谢你的提示。 - abuzze
4
对于未来的读者而言,你需要相应地执行gem install libv8 -v 'A.B.C.D'。在本文撰写时,版本号为3.16.14.15。 - Dave Land
1
如果您想安装特定版本的therubyracer,请使用以下命令:gem install therubyracer -v 'x.x.x' -- --with-v8-dir=/usr/local/opt/v8-315 - avital
1
看起来很像jottr的答案。也许可以向他打个招呼。 - omikes
5
对我而言,v8目录位于: /usr/local/opt/v8@3.15 - SamuelLJohnson
太好了,这对我也起作用。只需卸载所有先前版本的libv8即可。 - Xentatt

26

尝试先卸载libv8 gem,然后安装rubyracer,最后再安装libv8。

gem uninstall libv8
gem install therubyracer
gem install libv8 -- --with-system-v8

1
没有运气:( 错误信息中以下几行看起来很有意思: g++-4.6: error: x86_64: 没有那个文件或目录 g++-4.6: error: 无法识别的选项 '-arch' - user2490003
1
我发现在安装therubyracer之前先安装libv8效果更好。 - Chris Peters

24

Tertomgithub上发布的解决方案为我解决了这个问题,在尝试了其他所有在github问题和这里提出的解决方案之后。
我的系统配置与原作者完全相同。
这是在el capitan上的,所以并不是对问题的确切答案,但人们可能会发现这些信息很有帮助。

我在此引用它以供大家查看:

Solved the same problem

  • MacOS 10.11.2
  • ruby 1.9.3
  • libv8 3.16.14.13
  • therubyracer 0.12.2

--

brew tap homebrew/versions  
brew install v8-315  
brew link --force v8-315  
bundle install  
brew unlink v8-315

If you also cannot install libv8,

gem install libv8 --with-system-v8

or

bundle config build.libv8 --with-system-v8

1
这对我有效。我发现我需要指定libv8 gem的版本,以符合rubyracer所期望安装的要求。 - Paul Sturgess
1
是的,我相信 bundle config build.libv8 --with-system-v8 对我很关键。谢谢! - Nate Beaty
这是唯一对我有效的方法(并且在Catalina上尝试过,时间是2019年末)。 - Sam Johnson
非常有帮助,尽管homebrew/versions已被弃用。我的问题是当前链接与'/usr/local/bin/d8'相关联。取消链接并运行brew link --force v8-315对我很有效。2020年2月 - MacOS 10.15.3。 - Ruby版本1.9.3 - Bundler 1.16.4 - libv8版本13.16.14.19。 - Thomas

15

对于所有使用 macOS 10.15 的用户, brew 已经发生了变化,因此您需要执行以下命令。

brew install v8@3.15
gem install libv8 -v 'YOUR_VERSION' -- --with-system-v8
gem install therubyracer -v 'YOUR_VERSION' -- --with-v8-dir=/usr/local/opt/v8@3.15
bundle install

6

上述答案对我不起作用;我的bundler配置启用了disable-shared-gems,这会导致其它问题。

我正在使用Yosemite 10.10.1、Rails 3.2.x和Ruby 1.9.3p550。

以下代码片段在我的bin/setup中已经解决了这个问题。

if ! bundle show therubyracer; then
    bundle config build.libv8 --with-system-v8
    gem install --install-dir vendor/bundle libv8 -v 3.16.14.7
    gem install libv8 -v 3.16.14.7
    gem install --install-dir vendor/bundle therubyracer 
fi

4
我找到了一个解决上述问题的方法。
这更多是libv8和therubyracer之间的兼容性问题。
gem install libv8 -v '3.3.10.4' -- --with-system-v8

gem install therubyracer -v '0.10.2'

这应该没问题,因为两个版本都能兼容我。最初我试图安装therubyracer的0.12.0版本时遇到了问题。一旦我切换到0.10.2版本,一切都正常了。

我当前的操作系统是:Mavericks


4

我在 MacOS Mojave 10.14.2 上遇到了这个问题,当我找到安装包 v8-315 的位置和文件夹名称时,我成功地解决了它。

在我的情况下,它是在这里 /usr/local/opt/v8@3.15

为了修复这个问题,我运行了以下命令:

brew install v8-315
gem install libv8 -v '3.16.14.15' -- --with-system-v
gem install therubyracer -v '0.12.2' -- --with-system-v8 --with-v8-dir=/usr/local/opt/v8@3.15
bundle install

2
以下命令可以解决在Catalina使用bundler时出现的问题。
$ brew install v8@3.15
$ bundle config build.libv8 --with-system-v8
$ bundle config build.therubyracer --with-v8-dir=$(brew --prefix v8@3.15)
$ bundle install

2

在我的情况下

操作系统: Catalina, Ruby版本: 2.3.3, 使用的是rbenv(不是RVM), 我需要的therubyracer版本是:0.12.3(无关紧要)

我尝试了所有的解决方案,但对我起作用的是,请不要盲目地复制粘贴解决方案(因为我在我的情况下这样做了),首先阅读,然后根据需要更改以下命令中的版本。大多数命令在大多数现有答案中都是常见的,但对我起作用的是gem install therubyracer -- --with-v8-dir=$(brew --prefix v8-315)而不是gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315感谢Junji Zhi此答案中的评论。

1. brew install gcc
2. brew tap homebrew/versions   (If it wont work then below 2 steps, for latest MacOS version)
2.a. brew tap brewsci/bio
2.b. brew tap brewsci/science
3. brew install v8-315     (uninstall if v8 installed previously without '-315')
4. gem install libv8 -v '3.16.14.19' -- --with-system-v8   (Be careful with the libv8 version mentioned in this command, replace version number with one required)
5.a. gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315    (If it does not work then try below one, In my case below command worked)
5.b. gem install therubyracer -- --with-v8-dir=$(brew --prefix v8-315)

完成后,继续进行bundle install

注意:在安装gem时therubyracer,请检查正在安装的libv8版本是否与步骤4中提到的版本不同,如果不同,则可能无法安装therubyracer,所以只需执行一件事,即gem uninstall libv8,然后通过更改控制台中可以看到的therubyracer安装方法重复步骤4中的更改版本


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接