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

如何强制Fastlane使用指定Ruby版本解决Codepush运行错误?

强制Fastlane使用指定Ruby版本的解决方案

以下是针对MacOS 13.5环境下,让Fastlane 2.214.0强制使用rbenv配置的Ruby 2.7.4的可行方案:

方案1:确保rbenv Shell配置优先加载

  • 检查当前Shell配置文件(MacOS 13默认是~/.zshrc,旧版是~/.bash_profile),确认存在以下rbenv初始化代码:
    eval "$(rbenv init - zsh)"
    export PATH="$HOME/.rbenv/shims:$PATH"
    
  • 执行source ~/.zshrc刷新配置,运行ruby -v确认输出为ruby 2.7.4p191(或对应版本号)
  • 卸载原Fastlane并重新安装到当前Ruby环境:
    gem uninstall fastlane
    gem install fastlane -v 2.214.0
    
  • 验证Fastlane路径:执行which fastlane,应返回~/.rbenv/shims/fastlane而非系统路径

方案2:用项目本地Ruby版本锁定

  • 在项目根目录执行,生成.ruby-version文件锁定当前目录的Ruby版本:
    rbenv local 2.7.4
    
  • 项目根目录创建或修改Gemfile,明确指定Ruby和依赖版本:
    ruby '2.7.4'
    gem 'fastlane', '2.214.0'
    gem 'xcodeproj'
    
  • 安装项目依赖:
    bundle install
    
  • 后续通过bundle exec调用Fastlane,强制使用指定环境:
    bundle exec fastlane android codepush
    

方案3:直接指定Ruby解释器调用Fastlane

  • 获取rbenv管理的Ruby 2.7.4路径:
    rbenv which ruby
    
    输出示例:/Users/你的用户名/.rbenv/versions/2.7.4/bin/ruby
  • 用该路径直接调用Fastlane:
    /Users/你的用户名/.rbenv/versions/2.7.4/bin/ruby ~/.rbenv/shims/fastlane android codepush
    
  • 可添加别名简化调用,在~/.zshrc中加入:
    alias fastlane27="/Users/你的用户名/.rbenv/versions/2.7.4/bin/ruby ~/.rbenv/shims/fastlane"
    
    之后直接执行fastlane27 android codepush即可

方案4:移除系统级Fastlane(若存在)

  • 检查系统是否安装了全局Fastlane:
    which fastlane
    
    若输出包含/usr/bin/fastlane,说明存在系统级安装
  • 执行卸载:
    sudo gem uninstall fastlane
    
  • 确保rbenv的shims目录在PATH最前端(参考方案1的配置),重新安装Fastlane到rbenv环境即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 12:11:20