MacOS 上的 `/Library/Ruby/Site/2.6.0` 已损坏,无法运行 `brew`

MacOS 上的 `/Library/Ruby/Site/2.6.0` 已损坏,无法运行 `brew`

首先,当我打开终端时,出现了以下令人厌烦的输出:

Ignoring bigdecimal-2.0.0 because its extensions are not built. Try: gem pristine bigdecimal --version 2.0.0
Ignoring jaro_winkler-1.5.4 because its extensions are not built. Try: gem pristine jaro_winkler --version 1.5.4

/usr/bin/gem update --system

结果是:

Updating rubygems-update
Fetching rubygems-update-3.2.11.gem
Successfully installed rubygems-update-3.2.11
Parsing documentation for rubygems-update-3.2.11
Installing ri documentation for rubygems-update-3.2.11
Installing darkfish documentation for rubygems-update-3.2.11
Done installing documentation for rubygems-update after 181 seconds
Parsing documentation for rubygems-update-3.2.11
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 3.2.11
Error loading RubyGems plugin "/Users/gordonpn/.rvm/gems/ruby-3.0.0/plugins/gem-wrappers_plugin.rb": cannot load such file -- /Users/gordonpn/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/gem-wrappers-1.4.0/lib/rubygems_plugin.rb (LoadError)
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied @ rb_sysopen - /Library/Ruby/Site/2.6.0/rubygems.rb

愚蠢地修改了所有者sudo chown -R $(whoami) /Library/Ruby/Site/2.6.0/*并再次尝试上述命令。

现在,每次我运行brew,它都会出现以下输出:

Traceback (most recent call last):
 17: from /usr/local/Homebrew/Library/Homebrew/brew.rb:31:in `<main>'
 16: from /usr/local/Homebrew/Library/Homebrew/brew.rb:31:in `require_relative'
 15: from /usr/local/Homebrew/Library/Homebrew/global.rb:22:in `<top (required)>'
 14: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
 13: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
 12: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3/lib/active_support/core_ext/object/blank.rb:3:in `<top (required)>'
 11: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
 10: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  9: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/map.rb:3:in `<top (required)>'
  8: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  7: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  6: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/synchronization.rb:5:in `<top (required)>'
  5: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb:30:in `load_native_extensions'
  4: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb:30:in `each'
  3: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb:30:in `block in load_native_extensions'
  2: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb:62:in `try_load_c_extension'
  1: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- concurrent/concurrent_ruby_ext (LoadError)
 28: from /usr/local/Homebrew/Library/Homebrew/brew.rb:31:in `<main>'
 27: from /usr/local/Homebrew/Library/Homebrew/brew.rb:31:in `require_relative'
 26: from /usr/local/Homebrew/Library/Homebrew/global.rb:22:in `<top (required)>'
 25: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
 24: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
 23: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.3/lib/active_support/core_ext/object/blank.rb:3:in `<top (required)>'
 22: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
 21: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
 20: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/map.rb:3:in `<top (required)>'
 19: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
 18: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
 17: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/synchronization.rb:5:in `<top (required)>'
 16: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb:30:in `load_native_extensions'
 15: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb:30:in `each'
 14: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb:30:in `block in load_native_extensions'
 13: from /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb:62:in `try_load_c_extension'
 12: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require'
 11: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_require.rb:123:in `rescue in require'
 10: from /Library/Ruby/Site/2.6.0/rubygems.rb:210:in `try_activate'
  9: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:1036:in `find_by_path'
  8: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:822:in `stubs'
  7: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:972:in `dirs'
  6: from /Library/Ruby/Site/2.6.0/rubygems.rb:424:in `path'
  5: from /Library/Ruby/Site/2.6.0/rubygems.rb:380:in `paths'
  4: from /Library/Ruby/Site/2.6.0/rubygems.rb:380:in `new'
  3: from /Library/Ruby/Site/2.6.0/rubygems/path_support.rb:34:in `initialize'
  2: from /Library/Ruby/Site/2.6.0/rubygems/path_support.rb:67:in `split_gem_path'
  1: from /Library/Ruby/Site/2.6.0/rubygems/path_support.rb:75:in `default_path'
/Library/Ruby/Site/2.6.0/rubygems/defaults.rb:94:in `default_path': undefined local variable or method `user_home' for Gem:Module (NameError)

我尝试重新安装 xcode 命令行工具,因为我认为这会将系统 ruby​​ 和 ruby​​gems 恢复为默认设置。

这似乎是 Mac 系统 ruby​​gems 的问题,但说实话我并不确定。

我尝试进入/usr/local/Homebrewgit reset --hard,但没有帮助。

我一直不知道如何重新安装默认系统 ruby​​gems。也许我可以从 rvm 符号链接 ruby​​gems,但我也不确定如何做到这一点。

更新

操作系统版本:Big Sur 11.2.1

/usr/bin/gem返回以下内容:

Traceback (most recent call last):
    11: from <internal:gem_prelude>:4:in `<internal:gem_prelude>'
    10: from /Library/Ruby/Site/2.6.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
     9: from /Library/Ruby/Site/2.6.0/rubygems/dependency.rb:323:in `to_spec'
     8: from /Library/Ruby/Site/2.6.0/rubygems/dependency.rb:303:in `to_specs'
     7: from /Library/Ruby/Site/2.6.0/rubygems/dependency.rb:280:in `matching_specs'
     6: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:843:in `stubs_for'
     5: from /Library/Ruby/Site/2.6.0/rubygems/specification.rb:972:in `dirs'
     4: from /Library/Ruby/Site/2.6.0/rubygems.rb:424:in `path'
     3: from /Library/Ruby/Site/2.6.0/rubygems.rb:380:in `paths'
     2: from /Library/Ruby/Site/2.6.0/rubygems.rb:380:in `new'
     1: from /Library/Ruby/Site/2.6.0/rubygems/path_support.rb:36:in `initialize'
/Library/Ruby/Site/2.6.0/rubygems/defaults.rb:23:in `default_spec_cache_dir': undefined method `user_home' for Gem:Module (NoMethodError)

答案1

这对我有用(在 Big Sur 11.2.2 上)

rm -rf ~/.gem
git -C $(brew --repo) clean -xdf
brew update-reset

相关内容