Ubuntu 22.04下通过RVM安装Ruby 3.0.0失败:make编译build-ext出错
解决Ubuntu 22.04下RVM安装Ruby 3.0.0的编译失败问题
问题重现
- 环境:Ubuntu 22.04(x86_64)、GCC 11.4.0、最新稳定版RVM
- 操作:执行
rvm install 3.0.0 - 终端错误提示:
Error running '__rvm_make -j8', please read /home/ruby-dev/.rvm/log/1752077427_ruby-3.0.0/make.log - 日志核心错误内容:
cc1: note: unrecognized command-line option ‘-Wno-self-assign’ cc1: note: unrecognized command-line option ‘-Wno-parentheses-equality’ cc1: note: unrecognized command-line option ‘-Wno-constant-logical-operand’ make: *** [uncommon.mk:300: build-ext] Error 2
原因分析
Ruby 3.0.0源码中硬编码的部分GCC警告抑制选项,在GCC 11及以上版本已被移除或重命名,Ubuntu 22.04默认的GCC 11.4.0无法识别这些选项,导致编译流程中断。
解决方案
方法1:指定兼容的旧版本GCC编译
- 安装GCC 9(Ruby 3.0.0发布时的主流兼容编译器版本):
sudo apt update && sudo apt install gcc-9 g++-9 - 用RVM指定GCC 9安装Ruby 3.0.0:
rvm install 3.0.0 --with-gcc=gcc-9
方法2:手动修改源码编译选项
- 先下载Ruby 3.0.0源码但不执行编译:
rvm fetch 3.0.0 - 进入源码目录:
cd ~/.rvm/src/ruby-3.0.0 - 编辑
configure或common.mk文件,搜索并删除以下三个无效选项:-Wno-self-assign、-Wno-parentheses-equality、-Wno-constant-logical-operand - 重新配置并安装:
rvm install 3.0.0 --reconfigure
方法3:升级RVM到开发版(可能已修复兼容问题)
部分RVM开发分支已针对新GCC版本修复了该适配问题,可尝试升级后重新安装:
rvm get head rvm install 3.0.0
内容的提问来源于stack exchange,提问作者Muhammad Raihan
相关产品推荐
相关产品推荐

