You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用asdf安装Ruby后执行gem update --system遇架构不兼容错误求助

问题:执行gem update --system出现架构不兼容错误

我通过macOS 14 Sonoma的Ruby安装指南,使用asdf安装了Ruby,执行gem update --system命令后触发以下错误:

<internal:/usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:127:in `require': dlopen(/Users/andreasgerecke/.gem/ruby/3.3.0/gems/stringio-3.1.0/lib/stringio.bundle, 0x0009): tried: '/Users/andreasgerecke/.gem/ruby/3.3.0/gems/stringio-3.1.0/lib/stringio.bundle' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/andreasgerecke/.gem/ruby/3.3.0/gems/stringio-3.1.0/lib/stringio.bundle' (no such file), '/Users/andreasgerecke/.gem/ruby/3.3.0/gems/stringio-3.1.0/lib/stringio.bundle' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')) - /Users/andreasgerecke/.gem/ruby/3.3.0/gems/stringio-3.1.0/lib/stringio.bundle (LoadError)
  from <internal:/usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:127:in `require'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/remote_fetcher.rb:78:in `initialize'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/remote_fetcher.rb:56:in `new'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/remote_fetcher.rb:56:in `fetcher'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/spec_fetcher.rb:77:in `initialize'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/spec_fetcher.rb:43:in `new'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/spec_fetcher.rb:43:in `fetcher'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/commands/update_command.rb:141:in `fetch_remote_gems'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/commands/update_command.rb:168:in `highest_remote_name_tuple'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/commands/update_command.rb:233:in `rubygems_target_version'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/commands/update_command.rb:278:in `update_rubygems'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/commands/update_command.rb:99:in `execute'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/command.rb:326:in `invoke_with_build_args'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/command_manager.rb:254:in `invoke_command'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/command_manager.rb:193:in `process_args'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/command_manager.rb:151:in `run'
  from /usr/local/Cellar/ruby/3.3.0/lib/ruby/3.3.0/rubygems/gem_runner.rb:56:in `run'
  from /usr/local/opt/ruby/bin/gem:12:in `<main>'

解决方案

1. 确认当前Ruby运行架构

执行以下命令查看Ruby的平台信息:

ruby -e "puts RUBY_PLATFORM"

如果输出为x86_64-darwin23,说明当前终端在x86_64(Rosetta)模式下运行,但已安装的stringio是arm64架构编译的,导致不兼容。

2. 卸载不兼容的stringio版本

gem uninstall stringio

在提示中选择卸载3.1.0版本。

3. 重新编译安装适配当前架构的stringio

gem install stringio --platform=ruby

--platform=ruby参数会强制从源码编译gem,自动适配当前系统的CPU架构。

4. 重新执行gem更新

gem update --system

5. 若问题仍存在,重新安装适配架构的Ruby

# 卸载现有Ruby版本
asdf uninstall ruby 3.3.0
# 确保终端处于对应架构模式(arm64用原生终端,x86_64用Rosetta终端)
asdf install ruby 3.3.0
asdf global ruby 3.3.0

内容的提问来源于stack exchange,提问作者andreas gerecke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 05:12:17