Ruby-on-rails 安装 libv8 时出错:错误:无法构建 gem 本机扩展

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19673714/
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-02 22:58:35  来源:igfitidea点击:

Error installing libv8: ERROR: Failed to build gem native extension

ruby-on-railsrubywindowslibv8

提问by Canna

I made a rails project with,

我做了一个 Rails 项目,

rails new test_bootstrap.

succeeded.

成功了。

moved to the project dir and added the gems

移动到项目目录并添加了 gems

gem "therubyracer"
gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
gem "twitter-bootstrap-rails"

and run

并运行

bundle install

after that, i have this error.

在那之后,我有这个错误。

Installing libv8 (3.16.14.3)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

c:/RailsInstaller/Ruby1.9.3/bin/ruby.exe extconf.rb
creating Makefile
??? ??? ?? ? ????.                                                          ??? ??? ?? ?
????.                                                          ??? ??? ?? ? ????.

c:/RailsInstaller/Ruby1.9.3/lib/ruby/ge
ms/1.9.1/gems/libv8-3.16.14.3/ext/libv8/builder.rb:58:in `setup_python!': libv8 requires
python 2 to be installed in order to build, but it is currently not available (RuntimeErr
or) from c:/RailsInstaller/Ruby1.9.
3/lib/ruby/gems/1.9.1/gems/libv8-3.16.14.3/ext/libv8/builder.rb:42:in `block in build_lib
v8/builder.rb:42:in `block in build_libv8!'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/libv8-3.16.14.3/ext/lib
v8/builder.rb:40:in `chdir'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/libv8-3.16.14.3/ext/lib
v8/builder.rb:40:in `build_libv8!'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/libv8-3.16.14.3/ext/lib
v8/location.rb:24:in `install!'
        from extconf.rb:7:in `<main>'                                                    


Gem files will remain installed in c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/l
ibv8-3.16.14.3 for inspection.
Results logged to c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/libv8-3.16.14.3/ex
t/libv8/gem_make.out
An error occurred while installing libv8 (3.16.14.3), and Bundler cannot
continue.
Make sure that `gem install libv8 -v '3.16.14.3'` succeeds before bundling.

sorry for some Koreans. It says, It can't find the chosen path or something like that.

对不起一些韩国人。它说,它找不到选择的路径或类似的东西。

and i tried to run this command

我试着运行这个命令

gem install libv8 -v '3.16.14.3' 

throwing the same error.

抛出同样的错误。

回答by Gopal S Rathore

try this one:

试试这个:

gem install libv8 -v '3.16.14.3' -- --with-system-v8

Note :Because libv8 is the interface for the V8 engine used by therubyracer, you may need to use libv8, even if you have V8 installed already. If you wish to use your own V8 installation, rather than have it built for you, use the --with-system-v8option.

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

For more you can go through the documentation of libv8 on github

有关更多信息,您可以查看 github 上libv8文档

回答by Arpit Shah

How to resolve libv8/therubyracer issue

如何解决 libv8/therubyracer 问题

I encountered similar issue in which after installing libv8, error occurs installing therubyracer. Here is my solution:

我遇到了类似的问题,在安装 libv8 后,安装 therubyracer 时发生错误。这是我的解决方案:

$ gem install libv8 -v '3.16.14.3' -- --with-system-v8

$ bundle install

-- see error installing therubyracer --

-- 查看安装 therubyracer 时出错 --

$ gem uninstall libv8

$ brew install v8

$ gem install therubyracer

$ bundle install

-- see error installing libv8 --

-- 请参阅安装 libv8 时出错 --

$ gem install libv8 -v '3.16.14.3' -- --with-system-v8

回答by coding addicted

With homebrew this helps me to solve this error.

使用自制软件,这有助于我解决此错误。

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

Seen on rubyracer Github issues.

见于 ruby​​racer Github 问题。

回答by Anand Chavan

I tried the solution listed above command which looks very fine for installing individual gem, but for bundler users - you should use bundle config

我尝试了上面列出的命令的解决方案,它对于安装单个 gem 看起来非常好,但对于捆绑用户 - 你应该使用捆绑配置

Use

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

and

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

to configure bundler to take the parameters to be used while installing specific gem

配置 bundler 以获取安装特定 gem 时要使用的参数

回答by Litmus

I do not think you need therubyracergem on windows. It is a javascript runtime using V8 engine. Hence it is making an attempt to install libv8.

我认为您不需要therubyracer在 Windows 上使用 gem。它是一个使用 V8 引擎的 javascript 运行时。因此,它正在尝试安装libv8.

You can safely remove the gem from your Gemfile.

您可以安全地从 Gemfile 中删除 gem。

Rails is happy to use which ever runtime it can find. execjs,nodejsetc. are all possible options.

Rails 很乐意使用它可以找到的任何运行时。execjsnodejs等等都是可能的选择。

Microsoft already embeds JScript runtime for javascript on windows, and Rails uses it. See this for more

Microsoft 已经在 Windows 上为 javascript 嵌入了 JScript 运行时,Rails 使用它。查看更多

回答by Arman Ortega

Other workaround to fix the problem is to separate them in the Gemfile

解决问题的其他解决方法是在 Gemfile 中将它们分开

group :production do
 gem 'libv8', '~> 3.11.8.3'
 gem 'therubyracer', :platform => :ruby
end

And then run the bundle command: bundle install --without production

然后运行 ​​bundle 命令:bundle install --without production

回答by Rishav Bhardwaj

I was also unable to install this gem instead of using

我也无法安装这个 gem 而不是使用

--with-system-v8

once try to do bundle updatewhich worked fine for me

曾经尝试进行捆绑更新,这对我来说很好用

回答by Sojan V Jose

found this on github

github上找到了这个

assuming you have tried the mentioned steps above, installed v8-315 and v8 via brew.

假设您已尝试上述步骤,则通过 brew 安装了 v8-315 和 v8。

brew unlink v8
brew link --force v8-315
gem install therubyracer -v '0.12.2' -- --with-system-v8

回答by Hrk

That works for me. Put that in your Gemfile

这对我行得通。把它放在你的 Gemfile 中

gem 'libv8', '~>3.16.14.7'

宝石“libv8”,“~>3.16.14.7”

回答by d1jhoni1b

My issue wasn't related with therubyracerat all just libv8gem and as @rishav-bhardwaj pointed --with-system-v8didn't do the trick, instead i had to exec

我的问题尚未有相关therubyracer的一切只是libv8宝石和指出@ rishav-巴德瓦杰--with-system-v8没有做的伎俩,而不是我不得不EXEC

bundle update

bundle update

then

然后

bundle install

bundle install

and finally

最后

Bundle complete!

Bundle complete!

The error is gone!

错误消失了!

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. An error occurred while installing libv8 (3.16.14.7), and Bundler cannot continue. Make sure that `gem install libv8 -v '3.16.14.7'` succeeds before bundling.

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. An error occurred while installing libv8 (3.16.14.7), and Bundler cannot continue. Make sure that `gem install libv8 -v '3.16.14.7'` succeeds before bundling.