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

在自托管运行器(ARC)安装Ruby 3.1.2失败求助

在EKS自托管Runner(ubuntu-20.04-arm64)安装Ruby 3.1.2的解决建议

问题背景

使用actions-runner-controller在EKS部署的ubuntu-20.04-arm64自托管运行器上,尝试通过ruby/setup-ruby@v1安装Ruby 3.1.2时触发报错,提示需自行在$RUNNER_TOOL_CACHE路径手动安装;后续尝试RVM、rbenv方式均未成功。

报错信息:

Run ruby/setup-ruby@v1
with:
ruby-version: 3.1.2
bundler-cache: false

Error: The current runner (ubuntu-20.04-arm64) was detected as self-hosted because the platform does not match a GitHub-hosted runner image (or that image is deprecated and no longer supported).
In such a case, you should install Ruby in the $RUNNER_TOOL_CACHE yourself, for example using https://github.com/rbenv/ruby-build
You can take inspiration from this workflow for more details: https://github.com/ruby/ruby-builder/blob/master/.github/workflows/build.yml
$ ruby-build 3.1.2 /opt/hostedtoolcache/Ruby/3.1.2/arm64
Once that completes successfully, mark it as complete with:
$ touch /opt/hostedtoolcache/Ruby/3.1.2/arm64.complete
It is your responsibility to ensure installing Ruby like that is not done in parallel.

尝试的RVM命令:

sudo apt update
sudo apt install gnupg2
gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash
\curl -sSL https://get.rvm.io | bash -s stable --ruby
source /etc/profile
source \~/.rvm/scripts/rvm
rvm install ruby-3.1.2

解决方法

方案一:适配$RUNNER_TOOL_CACHE的ruby-build安装法(推荐)

该方法完全符合ruby/setup-ruby的要求,后续可直接复用setup-ruby的缓存逻辑:

  1. 安装编译Ruby的依赖包
    编译Ruby需要基础编译工具和依赖库,先补全:

    sudo apt update && sudo apt install -y build-essential libssl-dev libreadline-dev zlib1g-dev git
    
  2. 安装ruby-build
    通过git克隆工具到本地路径:

    git clone https://github.com/rbenv/ruby-build.git ~/.ruby-build
    echo 'export PATH="$HOME/.ruby-build/bin:$PATH"' >> ~/.bashrc
    source ~/.bashrc
    

    也可通过apt直接安装(系统仓库支持时):

    sudo apt install ruby-build
    
  3. 编译安装Ruby到指定工具缓存路径
    注意/opt/hostedtoolcache需要sudo权限:

    sudo mkdir -p /opt/hostedtoolcache/Ruby/3.1.2/arm64
    sudo chown -R $USER:$USER /opt/hostedtoolcache/Ruby
    ruby-build 3.1.2 /opt/hostedtoolcache/Ruby/3.1.2/arm64
    
  4. 创建标记文件完成缓存注册

    touch /opt/hostedtoolcache/Ruby/3.1.2/arm64.complete
    
  5. 验证安装

    export PATH="/opt/hostedtoolcache/Ruby/3.1.2/arm64/bin:$PATH"
    ruby -v  # 应输出ruby 3.1.2p20
    

方案二:修复RVM安装失败问题

若偏好RVM,需解决环境初始化和依赖缺失问题:

  1. 补全编译依赖
    安装缺失的编译工具和库:

    sudo apt update && sudo apt install -y build-essential libssl-dev libreadline-dev zlib1g-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev
    
  2. 正确初始化RVM环境
    RVM安装后需正确加载,避免路径错误:

    source ~/.rvm/scripts/rvm
    # 将初始化命令加入shell配置,永久生效
    echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc
    source ~/.bashrc
    
  3. 安装Ruby 3.1.2
    指定openssl路径适配arm64架构:

    rvm install 3.1.2 --with-openssl-dir=/usr/lib/ssl
    
  4. 设置全局Ruby版本

    rvm use 3.1.2 --default
    ruby -v  # 验证版本
    

关键注意事项

  • 并行安装问题:自托管runner若有多个并发任务,需确保Ruby安装过程不并行执行,可通过锁机制或在runner初始化阶段预先安装Ruby。
  • 权限问题:/opt/hostedtoolcache路径默认是root权限,需确保runner用户有读写权限,或用sudo执行安装命令。
  • arm64兼容性:部分Ruby版本编译需适配arm架构,确保依赖包为arm64版本(ubuntu-20.04默认仓库已支持)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 14:57:52