【问题标题】:Error installing libv8: ERROR: Failed to build gem native extension安装 libv8 时出错:错误:无法构建 gem 原生扩展
【发布时间】:2013-11-09 12:32:29
【问题描述】:

我做了一个 Rails 项目,

rails new test_bootstrap.

成功了。

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

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

然后运行

bundle install

之后,我有这个错误。

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.

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

我试图运行这个命令

gem install libv8 -v '3.16.14.3' 

抛出同样的错误。

【问题讨论】:

标签: ruby-on-rails ruby windows libv8


【解决方案1】:

试试这个:

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

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

更多内容可以查看libv8 on github的文档

【讨论】:

  • 我用那个。它编译正常,但运行'bundle'时我仍然有错误
  • 这部分工作但我在安装 therubyracer 时仍然遇到错误。它给了我一个类似于我之前使用 libv8 得到的错误“在捆绑之前确保某某成功”,但是当我尝试运行“gem install therubyracer”时,我得到“无法构建 gem 本机扩展”。错误
  • 我使用上面给出的参数作为 root 卸载并重新安装它。不工作。我的错误是An error occurred while installing libv8 (3.16.14.3), and Bundler cannot continue.Bundler::GemspecError: Could not read gem at /home/gitlab/gitlab/vendor/bundle/ruby/2.1.0/cache/libv8-3.16.14.3-x86_64-linux.gem. It may be corrupted. 我删除了整个cache folder 并重新运行bundle install --full-index --deployment --without development test postgres aws。工作。
  • 完美! gem install libv8 -v '3.16.14.3' -- --with-system-v8 在 OS X 10.11 上为我工作。
  • 在 OS X 10.15 上,bundle config build.libv8 --with-system-v8 有效。
【解决方案2】:

如何解决 libv8/therubyracer 问题

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

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

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

$ gem uninstall libv8

$ brew install v8

$ gem install therubyracer

$ bundle install

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

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

【讨论】:

  • 此回复中提到的步骤效果最好,我们需要先 gem install libv8,在 gem 安装 therubyracer 之前卸载以安装系统范围的 v8(gem install libv8 带有 --with-system-v8 标志) :)
  • 我认为您不需要第一步。在运行 bundle install 之前,使用 brew 安装系统 v8。然后手动安装 therubyracer gem 和 libv8 gem。并运行捆绑安装。但我还没试过。
  • 这也适用于我在 OSX 10.10.5 上使用 ruby​​ 2.1.2p95 for libv8 3.16.14.11
  • 记得将 '3.16.14.3' 更改为任何版本的 bundle 尝试运行,否则在运行 bundle install 时它将无法工作
  • 也适用于 10.12 (Sierra) 和 ruby​​ 1.9.3 for libv '3.16.14.11'
【解决方案3】:

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

使用

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

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

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

【讨论】:

  • 无论出于何种原因,我的捆绑配置需要以下内容才能找到正确的构建(使用下面编码上瘾者答案中的 brew install)bundle config build.therubyracer --with-v8-dir=/usr/local/opt/v8-315
【解决方案4】:

使用自制软件可以帮助我解决这个错误。

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

见于 ruby​​racer Github 问题。

对于 Homebrew 的新版本,因为 homebrew/versions 已被删除:

brew install v8@3.15

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

bundle install

@gorner 的建议(谢谢)

【讨论】:

  • 这对我有用,尽管它通过 brew 安装了旧版本的 v8。
  • 每次切换 ruby​​ 版本时,这个错误都会让我发疯。我觉得你可以尝试调整一下v8版本选项和获取路径。
  • 只有这个解决方案对我有用,感谢您的解决方案
  • @codingaddicted 你有没有想过这个错误会一直发生?我为一个新项目更新了 ruby​​ 和 rails,当我为我的旧项目打开一个新的 shell 时总是会出现这个错误。 rvm 应该可以处理这些版本问题,但是每次为我的旧项目打开一个新 shell 时,我都需要继续执行上面的命令。
  • @iamse7en 据我记得我必须为每个版本的 ruby​​ 运行这些。我在更新 ruby​​ 时看到了这个错误(但上个月我没有做太多的 ruby​​ 并且我没有使用不同的版本)。
【解决方案5】:

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

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

Rails 很乐意使用它可以找到的任何运行时。 execjs,nodejs 等都是可能的选项。

Microsoft 已经在 windows 上嵌入了用于 javascript 的 JScript 运行时,Rails 使用它。 See this for more

【讨论】:

    【解决方案6】:

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

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

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

    【讨论】:

    • 这与@Litmus 的答案结合使用效果很好,因为这显示了如何在不破坏 Windows 上的开发设置的情况下将 gem 保留在配置中(这可能与部署相关)。
    【解决方案7】:

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

    --with-system-v8
    

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

    【讨论】:

      【解决方案8】:

      github找到这个

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

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

      【讨论】:

        【解决方案9】:

        这对我有用。把它放在你的 Gemfile 中

        gem 'libv8', '~>3.16.14.7'

        【讨论】:

        • 这个解决方案把我带到bundle install --no-deployment 然后bundle install 为我工作
        【解决方案10】:

        我的问题与therubyracer 完全无关,只是libv8 gem 和@rishav-bhardwaj 指出--with-system-v8 没有成功,而是我不得不执行

        bundle update

        然后

        bundle install

        最后

        Bundle complete!

        错误消失了!

        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.

        【讨论】:

          【解决方案11】:

          就我而言,我通过要求解决了这种情况 'mini_racer', '~&gt; 0.2.6' 在我的 Gemfile 中

          然后 bundle install 命令起作用了。

          【讨论】:

            【解决方案12】:

            我在本地尝试了以下命令,效果很好:

            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
            

            【讨论】:

              【解决方案13】:

              2020 年 12 月,我们在 Debian 10 虚拟机以及我们的本地 Debian 10 桌面上遇到了编译错误——出乎意料。

              Bundle 尝试编译失败 Installing libv8 3.16.14.19 with native extensions

              错误日志说:

              IOError: [Errno 2] No such file or directory: '/home/username/application/shared/bundle/ruby/2.6.0/gems/libv8-7.3.492.27.1/vendor/build/config/gclient_args.gni'
              Running: gclient root
              Running: gclient config --spec 'solutions = [
                {
                  "url": "https://chromium.googlesource.com/v8/v8.git",
                  "managed": False,
                  "name": "v8",
                  "deps_file": "DEPS",
                  "custom_deps": {},
                },
              ]
              '
              Running: gclient sync --with_branch_heads
              Subprocess failed with return code 1.
              

              我们检查了Google v8 Repo 上的标签,发现请求的标签7.3.492.27.1 似乎在Google Repo 上不可用:

              libv8 did not install properly, expected binary v8 archive '/home/.../gyp
              /libv8_snapshot.a'to exist, but it was not found 
              (Libv8::Location::Vendor::ArchiveNotFound)
              

              我们唯一的解决方案是从 Gemfile 中完全删除 therubyracer :-(

              【讨论】:

                【解决方案14】:

                我解决了这个问题:

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

                【讨论】:

                  【解决方案15】:

                  试试

                  gem "therubyracer", "~> 0.10.2" 到 Gemfile

                  它会安装依赖的gem libv8 (3.3.10.4),构建gem原生扩展失败的问题得到解决。

                  【讨论】:

                    【解决方案16】:

                    使用以下命令解决了 libv8 3.16.14.7 问题:

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

                    然后bundle install成功完成。

                    【讨论】:

                      【解决方案17】:

                      我觉得这与 libv8 关系不大,而与 therubyracer 关系更大。

                      在 Rails 应用程序上运行捆绑安装时,我收到了同样的错误。如果您也遇到过类似的情况,请尝试在 bundle 之外安装 gem,如下所示:

                      gem install therubyracer

                      然后运行捆绑安装。我希望这对你也有用。

                      【讨论】:

                        【解决方案18】:

                        我在使用 libv8mini_racer 时也遇到了问题。解决了问题

                        brew install v8
                        
                        bundle update libv8 mini_racer
                        

                        使用最新版本的mini_racer 0.2.10libv8 7.3.492.27 效果很好。

                        【讨论】:

                          猜你喜欢
                          • 2017-06-28
                          • 2012-04-19
                          • 2019-01-12
                          • 2013-11-14
                          • 2013-12-17
                          • 2019-04-03
                          • 1970-01-01
                          • 2012-11-02
                          • 1970-01-01
                          相关资源
                          最近更新 更多