由于 mac 上的 therubyracer 错误,无法安装 Jekyll

Not able to install Jekyll because of therubyracer error on mac

我正在尝试 运行 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.3 的 Mac 机器上尝试此操作,Ruby 版本为 ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]gem 版本为 3.0.3.

如果有人能告诉我如何修复这个错误并且我可以安装并且 运行 Jekyll 成功,那将会很有帮助。

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

请尝试以下步骤:

  1. 清理你的系统
gem uninstall -a libv8
gem uninstall -a therubyracer
  1. 在安装 therubyracer
  2. 之前安装特定版本的 libv8
gem install libv8 -v '3.16.14.15'
  1. 安装therubyracer
gem install therubyracer -v '0.12.3'
  1. libv8 更新到您的 gemfile
  2. 中指定的版本
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