微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

由于 mac 上的 ruby​​racer 错误,无法安装 Jekyll

如何解决由于 mac 上的 ruby​​racer 错误,无法安装 Jekyll

我正在尝试运行 Jekyll 并且我在 Gemfile

中有以下内容
source "https://rubygems.org"
gem 'jekyll-auth'
gem 'redcarpet'
gem 'jekyll-lunr-js-search'
gem 'rouge'
gem 'jekyll-sitemap'

我正在运行 bundle install 来安装指定的依赖项。一切正常,直到它尝试安装名为 therubyracer 的 gem。然后通过抛出以下错误来停止进程:

Installing nokogiri 1.11.3 (x86_64-darwin)
Fetching libv8 3.16.14.19
Installing libv8 3.16.14.19 with native extensions
Fetching ref 2.0.0
Installing ref 2.0.0
Fetching therubyracer 0.12.3
Installing therubyracer 0.12.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/therubyracer-0.12.3/ext/v8
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r
./siteconf20210430-34242-1i9kf2u.rb extconf.rb --with-v8-dir\=/usr/local/opt/v8@3.15
checking for -lpthread... yes
checking for -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
    --without-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=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
    --with-pthreadlib
    --without-pthreadlib
    --with-objclib
    --without-objclib
    --enable-debug
    --disable-debug
    --with-v8-dir
    --with-v8-include
    --without-v8-include=${v8-dir}/include
    --with-v8-lib
    --without-v8-lib=${v8-dir}/lib
/Library/Ruby/Gems/2.6.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:50:in `configure': By using
--with-system-v8,you have chosen to use the version  (Libv8::Location::System::NotFoundError)
of V8 found on your system and *not* the one that is bundled with
the libv8 rubygem.

However,your system version of v8 Could not be located.

Please make sure your system version of v8 that is compatible
with 3.16.14.19 installed. You may need to use the
--with-v8-dir option if it is installed in a non-standard location
    from /Library/Ruby/Gems/2.6.0/gems/libv8-3.16.14.19/lib/libv8.rb:7:in `configure_makefile'
    from extconf.rb:32:in `<main>'

To see why this extension Failed to compile,please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/therubyracer-0.12.3/mkmf.log

extconf Failed,exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/therubyracer-0.12.3 for inspection.
Results logged to
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/therubyracer-0.12.3/gem_make.out

An error occurred while installing therubyracer (0.12.3),and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.12.3' --source 'https://rubygems.org/'` succeeds
before bundling.

In Gemfile:
  jekyll-lunr-js-search was resolved to 3.3.0,which depends on
    therubyracer

现在为了修复这个错误,我尝试了一些帖子中指定的以下命令

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 config build.libv8 --with-system-v8
bundle config build.therubyracer --with-v8-dir=$(brew --prefix v8@3.15)

但是没有运气。我尝试在命令中为 v8 指定基于 brew 的路径,如下所示:

sudo gem install therubyracer -- --with-v8-dir= /usr/local/Cellar/v8@3.15

即使做了所有这些之后,我仍然遇到同样的错误,它说 our system version of v8 Could not be located.

我正在一台安装了 BigSur 11.2.3Ruby 版本为 ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]gem 版本为 3.0.3 的 Mac 机器上尝试此操作。>

如果有人能告诉我如何修复此错误并且我可以成功安装和运行 Jekyll,这将是非常有帮助的。

解决方法

两年前我遇到了同样的问题。我发现 libv8 3.16.14.19therubyracer 0.12.3 不兼容并写了一个 post 来记录我的解决方案。

尝试以下步骤:

  1. 清理您的系统
gem uninstall -a libv8
gem uninstall -a therubyracer
  1. 在安装 libv8 之前先安装具有特定版本的 therubyracer
gem install libv8 -v '3.16.14.15'
  1. 安装therubyracer
gem install therubyracer -v '0.12.3'
  1. libv8 更新到您的 gemfile 中指定的版本
bundle

macOS BigSur 11.2 可能仍有问题。

如果它在第 2 步中引发 fatal error: 'climits' file not found,试试这个:

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

如果它在第 3 步中引发错误,请尝试以下操作:

brew install v8-315
gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。