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

轨道中止!当运行 `rails new` 和 `rails s` 时,nokogiri 和 dlopen 出现加载错误

如何解决轨道中止!当运行 `rails new` 和 `rails s` 时,nokogiri 和 dlopen 出现加载错误

我在 macOS 上尝试使用 rails new MyBlog -T --database:postgresql 启动一个新的 Rails 应用程序,但出现以下错误对话框(rails s 也是如此:

LoadError: cannot load such file -- nokogiri/nokogiri
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:89:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `block in require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:299:in `load_dependency'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `require'
/Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.2-arm64-darwin/lib/nokogiri/extension.rb:25:in `rescue in <main>'
/Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.2-arm64-darwin/lib/nokogiri/extension.rb:4:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `block in require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:299:in `load_dependency'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `require'
/Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.2-arm64-darwin/lib/nokogiri.rb:11:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `block in require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:299:in `load_dependency'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `require'
/Library/Ruby/Gems/2.6.0/gems/actiontext-6.1.3/lib/action_text.rb:6:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `block in require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:299:in `load_dependency'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `require'
/Library/Ruby/Gems/2.6.0/gems/actiontext-6.1.3/lib/action_text/engine.rb:8:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `block in require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:299:in `load_dependency'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `require'
/Users/me/CodeProjects/MyBlog/config/application.rb:12:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:53:in `require_relative'
/Users/me/CodeProjects/MyBlog/Rakefile:4:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
/Library/Ruby/Gems/2.6.0/gems/railties-6.1.3/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/Library/Ruby/Gems/2.6.0/gems/railties-6.1.3/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/Library/Ruby/Gems/2.6.0/gems/railties-6.1.3/lib/rails/command.rb:52:in `invoke'
/Library/Ruby/Gems/2.6.0/gems/railties-6.1.3/lib/rails/commands.rb:18:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Users/me/CodeProjects/MyBlog/bin/rails:5:in `<top (required)>'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `load'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `call'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/lib/spring/client/command.rb:7:in `call'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/lib/spring/client.rb:30:in `run'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/bin/spring:49:in `<top (required)>'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `load'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<top (required)>'
/Users/me/CodeProjects/MyBlog/bin/spring:10:in `block in <top (required)>'
/Users/me/CodeProjects/MyBlog/bin/spring:7:in `tap'
/Users/me/CodeProjects/MyBlog/bin/spring:7:in `<top (required)>'
bin/rails:2:in `load'
bin/rails:2:in `<main>'

Caused by:
LoadError: dlopen(/Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.2-arm64-darwin/lib/nokogiri/2.6/nokogiri.bundle,0x0009): Could not use '/Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.2-arm64-darwin/lib/nokogiri/2.6/nokogiri.bundle' because it is not a compatible arch - /Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.2-arm64-darwin/lib/nokogiri/2.6/nokogiri.bundle
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `block in require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:299:in `load_dependency'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `require'
/Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.2-arm64-darwin/lib/nokogiri/extension.rb:6:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `block in require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:299:in `load_dependency'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `require'
/Library/Ruby/Gems/2.6.0/gems/nokogiri-1.11.2-arm64-darwin/lib/nokogiri.rb:11:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `block in require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:299:in `load_dependency'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `require'
/Library/Ruby/Gems/2.6.0/gems/actiontext-6.1.3/lib/action_text.rb:6:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `block in require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:299:in `load_dependency'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `require'
/Library/Ruby/Gems/2.6.0/gems/actiontext-6.1.3/lib/action_text/engine.rb:8:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `block in require'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:299:in `load_dependency'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.3/lib/active_support/dependencies.rb:332:in `require'
/Users/me/CodeProjects/MyBlog/config/application.rb:12:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:53:in `require_relative'
/Users/me/CodeProjects/MyBlog/Rakefile:4:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
/Library/Ruby/Gems/2.6.0/gems/railties-6.1.3/lib/rails/commands/rake/rake_command.rb:20:in `block in perform'
/Library/Ruby/Gems/2.6.0/gems/railties-6.1.3/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/Library/Ruby/Gems/2.6.0/gems/railties-6.1.3/lib/rails/command.rb:52:in `invoke'
/Library/Ruby/Gems/2.6.0/gems/railties-6.1.3/lib/rails/commands.rb:18:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Users/me/CodeProjects/MyBlog/bin/rails:5:in `<top (required)>'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `load'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `call'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/lib/spring/client/command.rb:7:in `call'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/lib/spring/client.rb:30:in `run'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/bin/spring:49:in `<top (required)>'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `load'
/Library/Ruby/Gems/2.6.0/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<top (required)>'
/Users/me/CodeProjects/MyBlog/bin/spring:10:in `block in <top (required)>'
/Users/me/CodeProjects/MyBlog/bin/spring:7:in `tap'
/Users/me/CodeProjects/MyBlog/bin/spring:7:in `<top (required)>'
bin/rails:2:in `load'
bin/rails:2:in `<main>'

我尝试了 bundle updatebundle install,没有任何改变。

当我尝试 gem uninstall nokogiri 时,我得到

gem uninstall nokogiri

Select gem to uninstall:
 1. nokogiri-1.11.2-arm64-darwin
 2. nokogiri-1.11.2-x86_64-darwin
 3. All versions
>

我遇到了 3 个

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

有人可以帮我吗?

解决方法

权限错误可能意味着该 gem 已被 root 用户安装,执行类似 sudo gem install 的操作,这意味着您也必须使用 sudo 将其删除。

现在 nokogiri gem 通常依赖于所谓的原生扩展,即必须为特定类型的平台编译的代码。

在这里我们可以看到您为 x86_64-darwin 和 arm64-darwin 安装了 nokogiri。

这里的 darwin 指的是您的操作系统 (mac OS)

x86_64 是为 64 位版本的英特尔处理器系​​列命名的代码,也称为 amd64,因为第一个此类处理器是由 AMD 开发的。

arm64 是另一种基于 ARM 的计算机架构,由于其能耗较低,因此常用于手机和平板电脑。

arm64-darwin 指的是新的 Apple Silicon 架构。

现在 dlopen 是加载共享库 (.so) 的 C api,它清楚地报告:

 could not use '.../nokogiri-1.11.2-arm64-darwin/l...' because it is not a compatible arch

所以你知道它在你的系统上不可用。这意味着您可能可以安全地删除它。

此外,您可以尝试使用 asdfrbenvrvm 或类似的东西来管理您的 ruby​​ 版本,这也将使您的 gems(取决于您的配置方式)保持在您的用户文件夹,因此您无需担心 sudo

,

我在本地环境(MAC OS Catalina 10.15.7、ruby 2.6.3p62、Rails 6.1.3)中遇到了同样的问题,我可以通过执行以下操作来解决它。

# Remove all versions of the nokogiri gem
sudo gem uninstall nokogiri
brew install libxml2
gem install nokogiri -- --use-system-libraries \
--with-xml2-include=$(brew --prefix libxml2)/include/libxml2

然后从 Gemfile.lock 中删除 nokogiri (1.11.2-arm64-darwin) 依赖项。

nokogiri (1.11.2-arm64-darwin)
  racc (~> 1.4)

通过 brew 安装 libxml2 并将其用于 nokogiri gem 的想法我是从这里得到的:https://nokogiri.org/tutorials/installing_nokogiri.html#macos-error-use-of-undeclared-identifier-lzma_ok(解决方案 2)

希望有帮助!快乐的 Rails 编码!


更新 您可能不需要卸载 nokogiri 并安装 libxml2。只需从 Gemfile.lock 中删除 nokogiri (1.11.2-arm64-darwin) 即可解决问题

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