ruby `gem install therubyracer` 在 Mac OS X Lion 上失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10905820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 05:10:35  来源:igfitidea点击:

`gem install therubyracer` fails on Mac OS X Lion

rubyrubygemsv8

提问by David J.

I would appreciate some help in getting gem install therubyracerto work. Here is the error:

我希望能在gem install therubyracer上班时得到一些帮助。这是错误:

$ gem install therubyracer
Building native extensions.  This could take a while...
ERROR:  Error installing therubyracer:
    ERROR: Failed to build gem native extension.

        /Users/david/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for main() in -lobjc... yes
*** 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/david/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
    --with-objclib
    --without-objclib
extconf.rb:15:in `<main>': undefined method `include_path' for Libv8:Module (NoMethodError)

Here are some notable steps that I ran before the error. They worked fine:

以下是我在错误之前运行的一些值得注意的步骤。他们工作得很好:

$ gem install libv8
$ brew install v8

My environment is:

我的环境是:

  • Mac OS X Lion 10.7.4
  • ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0] (via rvm)
  • V8 version 3.9.24 (via homebrew)
  • Mac OS X Lion 10.7.4
  • ruby 1.9.3p194(2012-04-20 修订版 35410)[x86_64-darwin11.4.0](通过 rvm)
  • V8 版本 3.9.24(通过自制软件)

回答by David J.

This worked for me:

这对我有用:

$ gem uninstall libv8
$ gem install therubyracer

(A big thanks to http://www.ruby-forum.com/topic/4306127)

(非常感谢http://www.ruby-forum.com/topic/4306127

回答by Ken Mazaika

gem uninstall libv8
brew install v8
gem install therubyracer

回答by Mars Redwyne

But, whyis this happening, you ask? And why does uninstalling libv8and reinstalling therubyracerfix the problem?

但是,你问为什么会发生这种情况?为什么卸载libv8并重新安装可以therubyracer解决问题?

The answer is at the bottom of the error message (from orig post). Ignore the stuff about

答案在错误消息的底部(来自原帖)。忽略有关的东西

probably lack of necessary libraries and/or headers

This is an incorrect assumption by whoever wrote that error message. At the bottom, you see what Ruby has to say about it:

这是编写该错误消息的人的错误假设。在底部,您会看到 Ruby 对此有何评论:

undefined method `include_path' for Libv8:Module

In my case, I was trying to install therubyracer-0.9.8with bundle install, and for some reason, it was trying to use my copy of libv8-3.11.8.13, which had been installed at some point, probably as a dependency of some other gem.

就我而言,我试图安装therubyracer-0.9.8使用bundle install,出于某种原因,有人试图用我的副本libv8-3.11.8.13,其中已经安装在某些时候,可能是因为其他一些宝石的依赖。

I don't know why it was trying to use the newer version, because therubyracer.gemspeccontains s.add_dependency "libv8", "~> 3.3.10". And my Gemfile.locksays to use libv8 (3.3.10.2). But alas, that is indeed what was happening.

我不知道它为什么要尝试使用较新的版本,因为therubyracer.gemspec包含s.add_dependency "libv8", "~> 3.3.10". 我Gemfile.lock说要使用libv8 (3.3.10.2). 但唉,这确实是正在发生的事情。

And it's true that Libv8:Moduledoes nothave the method include_pathin libv8-3.11.8.13, but it doesin libv8-3.3.10.2

而这是真的,Libv8:Module不能有方法include_pathlibv8-3.11.8.13,但它确实libv8-3.3.10.2

So that is why uninstalling allof your versions of libv8and then re-installing therubyracerworks. Because all the versions of libv8that do not havethe method include_pathare removed completely, and the libv8that does havethe method includepath is reinstalled when you reinstall of therubyracer.

所以这就是卸载所有版本libv8然后重新安装的原因therubyracer。因为所有的版本libv8没有做的方法include_path是完全去除,而libv8确实有方法include,当你重新安装的路径重新安装therubyracer

回答by Abe Petrillo

Considering none if the above worked for me 100%, I thought I'd post what did (as part of a rails project):

如果上述内容对我 100% 有效,则考虑没有,我想我会发布所做的事情(作为 Rails 项目的一部分):

gem uninstall libv8
bundle update therubyracer

This made sure I got the latest therubyracer, and also a more recent version of libV8, and seem to fix the multiple issues I was hitting, from missing libv8.a files, to undefined methods.

这确保我获得了最新therubyracer版本的libV8,并且似乎解决了我遇到的多个问题,从缺少 libv8.a 文件到未定义的方法。

回答by szpapas

At last I use therubyracer 0.11.0beta5 as a solution.

最后我使用 therubyracer 0.11.0beta5 作为解决方案。

Using therubyracer (0.11.0beta5)

使用 therubyracer (0.11.0beta5)

add following on Gemfile

在 Gemfile 上添加以下内容

gem 'therubyracer', '~> 0.11.0beta5'
group :libv8 do
  gem 'libv8', "~> 3.11.8"
end

then bundle install

然后 bundle install

Mac OSX 10.8 Moutain Lion

Mac OSX 10.8 山狮

回答by cwd

If you need 0.11.3and it's failing give this a shot for Mac OS X 10.9...

如果您需要0.11.3并且失败了,请为 Mac OS X 10.9 试一试...

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

See this issuefor more details.

有关更多详细信息,请参阅此问题

You probably don't need the -- --with-system-v8on the last line but I did it just to be safe since I saw it start doing Fetching: libv8-3.11.8.17-x86_64-darwin-13.gem (1%)when I ran the command...

您可能不需要-- --with-system-v8最后一行的 ,但我这样做只是为了安全,因为我Fetching: libv8-3.11.8.17-x86_64-darwin-13.gem (1%)在运行命令时看到它开始执行...

Anyhow, it worked for me when all the other things did not.

无论如何,当所有其他事情都不起作用时,它对我有用。

回答by Paul Fioravanti

For anyone encountering this issue on Mac OSX 10.8 Mountain Lion when attempting to upgrade their Gemfilewith gem 'therubyracer', '0.11.0', just upgrading the system libv8gem worked for me (no uninstallation of any other gem necessary):

对于任何试图自己升级的时候在Mac OSX 10.8山狮遇到此问题的Gemfilegem 'therubyracer', '0.11.0',只是系统升级libv8宝石对我来说有效(无需任何其他宝石的卸载):

$ gem update libv8
$ bundle install

Edit

编辑

If you use Travis-CI(or other CI tools located on other servers, I assume), you will need to explicitly add the libv8gem to your Gemfileas well:

如果您使用Travis-CI(或位于其他服务器上的其他 CI 工具,我假设),您还需要将libv8gem显式添加到您的Gemfile中:

Gemfile

文件

gem 'libv8', '3.11.8.3'

then bundle installas usual. Just note that libv8can take a significant amount of time to install and I've noticed that it may end up being the cause of going over Travis CI's timeout limits, causing your build to fail. You can mitigate this slightly be not including development environment gems in your builds:

然后bundle install像往常一样。请注意,安装libv8可能需要大量时间,我注意到它可能最终导致超过Travis CI 的超时限制,从而导致构建失败。您可以稍微缓解这种情况,不在您的构建中包含开发环境 gems:

.travis.yml

.travis.yml

# ...
bundler_args: --binstubs=./bundler_stubs --without development

Update

更新

Yep, pretty much all my Travis builds timeout and fail because of this. If anyone knows a way to solve this problem (I would hope "downgrade therubyracer" is a last resort), please leave a comment!

是的,我几乎所有的 Travis 构建都因此超时并失败。如果有人知道解决这个问题的方法(我希望“降级therubyracer”是最后的手段),请发表评论!

Update 2

更新 2

This may not work for all apps, but it seems that my Rails 3.2.9 apps didn't actually need therubyraceror libv8after all. After removing those gems from my Gemfile, I confirmed that my specs passed, pushed again to Travis and it built successfully. So, I guess getting rid of those gems (if you're not sure you actually need them) is at least worth a try.

这可能不适用于所有应用程序,但似乎我的 Rails 3.2.9 应用程序实际上并不需要therubyracer或根本不需要libv8。从我的Gemfile 中删除这些 gem 后,我确认我的规范通过了,再次推送到 Travis 并成功构建。所以,我想摆脱这些宝石(如果你不确定你是否真的需要它们)至少值得一试。

Update 3

更新 3

Thanks to Paul Annesleyfor confirming that if you're on Mac OS X 10.8 Mountain Lion, you don't need therubyracergem at all since the OS already comes bundled with Apple JavaScriptCore, its own Javascript runner. At the time of the original answer, I was on Snow Leopard and hence needed it.

感谢Paul Annesley确认如果您使用的是 Mac OS X 10.8 Mountain Lion,您根本不需要 therubyracergem,因为该操作系统已经捆绑了 Apple JavaScriptCore,它自己的 Javascript 运行程序。在最初的答案时,我在雪豹上,因此需要它。

回答by Alex Weber

For me, removing the Gemfile.lock file and running bundle installworked it's magic.

对我来说,删除 Gemfile.lock 文件并运行bundle install它很神奇。

回答by Colby Blair

OSX 10.8.2, ruby 1.9.3p125

OSX 10.8.2,红宝石 1.9.3p125

None of the above worked for me... I got tired of trying to find the right gem for my environment, so I just soft linked to the g++ target this things was missing:

以上都不适合我......我厌倦了尝试为我的环境找到合适的 gem,所以我只是软链接到 g++ 目标,这东西丢失了:

sudo ln -s `which g++` /usr/bin/g++-4.2

Not as helpfully for remote deployments, but get the job done on my workstation.

对远程部署没有帮助,但可以在我的工作站上完成工作。

回答by richardun

I got a similar issue, but it was also complaining about not finding g++-4.2. I didhave XCode command line tools installed, but it was looking for /usr/bin/g++-4.2, I had g++ (which was a symbolic link pointing to llvm-g++-4.2). Anyway, I just created a symbolic link to g++ and tried the bundle install again... it worked!

我遇到了类似的问题,但它也抱怨找不到 g++-4.2。我确实安装了 XCode 命令行工具,但它正在寻找 /usr/bin/g++-4.2,我有 g++(这是一个指向 llvm-g++-4.2 的符号链接)。无论如何,我刚刚创建了一个指向 g++ 的符号链接,并再次尝试了 bundle install ......它起作用了!

$ cd /usr/bin

$ cd /usr/bin

$ sudo ln -s g++ g++-4.2

$ sudo ln -s g++ g++-4.2