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

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编译

  1. 安装GCC 9(Ruby 3.0.0发布时的主流兼容编译器版本):
    sudo apt update && sudo apt install gcc-9 g++-9
    
  2. 用RVM指定GCC 9安装Ruby 3.0.0:
    rvm install 3.0.0 --with-gcc=gcc-9
    

方法2:手动修改源码编译选项

  1. 先下载Ruby 3.0.0源码但不执行编译:
    rvm fetch 3.0.0
    
  2. 进入源码目录:
    cd ~/.rvm/src/ruby-3.0.0
    
  3. 编辑configure或common.mk文件,搜索并删除以下三个无效选项:
    -Wno-self-assign、-Wno-parentheses-equality、-Wno-constant-logical-operand
  4. 重新配置并安装:
    rvm install 3.0.0 --reconfigure
    

方法3:升级RVM到开发版(可能已修复兼容问题)

部分RVM开发分支已针对新GCC版本修复了该适配问题,可尝试升级后重新安装:

rvm get head
rvm install 3.0.0

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 17:22:44