安装“gem”时出错,Bundler 无法继续 Mac OS - 大苏尔

问题描述

当我升级到 Catalina 时,这个错误发生在我之前的 nio4r gem 上,@dmitry barkov 回答了这个错误。在使用 json、oj 和 therubyracer 进行大 sur 升级之后,现在发生了类似的问题(尝试使用 nio4r 的解决方案,但没有运气)。当我运行 gem list 时,我看到 gems 已安装但捆绑安装失败。所以我尝试了 bundle update json oj therubyracer。它适用于 json 和 oj 但对于 therubyracer,它会引发错误

therubyracer 错误 -->

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/me/.gem/gems/therubyracer-0.12.2/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
./siteconf20210106-9670-edtaxk.rb extconf.rb --with-v8-dir\=/usr/local/opt/v8
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
/Users/me/.gem/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.

json 错误 -->

/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
./siteconf20210106-29155-126itgi.rb extconf.rb
creating Makefile

current directory: /Users/me/.gem/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR=" clean

current directory: /Users/me/.gem/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
generator.c:861:25: error: use of undeclared identifier 'rb_cFixnum'
    } else if (klass == rb_cFixnum) {
                        ^
generator.c:863:25: error: use of undeclared identifier 'rb_cBignum'
    } else if (klass == rb_cBignum) {
                        ^
2 errors generated.
make: *** [generator.o] Error 1

make Failed,exit code 2
*** LOCAL GEMS ***

bigdecimal (1.2.8)
bundler (1.17.3)
json (1.8.3)
libv8 (3.16.14.17)
oj (2.15.0)
rake (10.4.2)
ref (2.0.0)
therubyracer (0.12.3)

checking for v8.h... no 我知道这可能是一个问题,所以这是我尝试修复它的方法,但未成功 ->

brew install v8-315
gem uninstall -a libv8
bundle config build.therubyracer --with-v8-dir=$(brew --prefix v8@3.15)
gem install libv8 -v '3.16.14.17' — —with-system-v8
gem uninstall -a therubyracer
bundle config build.libv8 --with-system-v8
gem install therubyracer -v '0.12.2' -- --with-v8-dir=$(brew --prefix v8@3.15)

当我执行 bundle update 时,它​​在解决依赖项时卡住了……我让它运行了 12 个小时,然后我放弃了。 当我删除我的 gemfile.lock 并运行 bundle install 时,它再次陷入解决依赖关系的问题......

我使用的是 ruby​​ v 2.3.1 捆绑器版本 1.17.3

我注意到的一件事是路径 /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby 显示 2.6.0,但我使用的是 2.3.1(通过运行 rbenv local 和 ruby​​ -v 确认)

如果需要任何其他信息,请告诉我。任何帮助将不胜感激。

解决方法

我最终删除了项目文件夹并克隆了一个新文件夹。删除了所有宝石,重新安装了 rbenv,就像@taylorthurlow 指出的那样。

一切顺利,捆绑安装是绿色的。