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

Mac M1 上使用asdf安装Ruby 3.1.4时编译错误求助

解决asdf安装Ruby 3.1.4时的readline编译错误

这个错误是Ruby 3.1.4与新版readline的宏定义冲突导致的,以下是无需卸载asdf或Homebrew的解决步骤:

方法一:指定Ruby编译时使用Homebrew的readline

让Ruby明确调用Homebrew安装的readline库和头文件,执行以下命令:

export RUBY_CONFIGURE_OPTS="--with-readline-dir=$(brew --prefix readline)"
asdf install ruby 3.1.4

方法二:降级readline到兼容版本

如果方法一无效,说明当前readline版本过高,可降级到Ruby 3.1.4兼容的8.1版本:

  1. 卸载当前readline(忽略依赖避免影响其他软件):
brew uninstall --ignore-dependencies readline
  1. 安装8.1版本:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/8a042f3b4f6e32f227e6cf4d69a207f5f597a017/Formula/readline.rb
  1. 锁定版本防止被自动更新:
brew pin readline
  1. 再次执行方法一的命令安装Ruby 3.1.4

方法三:用补丁修复版本冲突

如果不想降级readline,可给Ruby 3.1.4打适配新版readline的补丁:

export RUBY_PATCH_URL="https://raw.githubusercontent.com/rbenv/ruby-build/master/patches/ruby/3.1.4/readline-8.2.patch"
asdf install ruby 3.1.4

验证安装

安装完成后,切换到该版本并确认正常工作:

asdf global ruby 3.1.4
ruby -v
irb # 测试readline功能是否正常

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 12:32:35