React Native 0.71.1 iOS新架构启用时Ruby版本不匹配问题排查
Ruby版本不匹配问题排查(React Native 0.71.1 iOS新架构)
问题背景
在React Native 0.71.1新项目中启用iOS新架构时,遭遇Ruby版本不匹配错误。已通过rbenv安装并全局设置Ruby 2.7.6,终端执行ruby --version显示版本正确,但运行bundle install && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install时仍报错:
Your Ruby version is 2.6.10, but your Gemfile specified 2.7.6
已尝试的操作:
- 执行
brew update、brew install ruby-build、brew install rbenv rbenv install 2.7.6并设置rbenv global 2.7.6- 在
~/.zshrc中添加rbenv环境变量配置
可能的遗漏步骤
1. 重新加载终端环境变量
修改.zshrc后,需手动加载最新配置或重启终端:
source ~/.zshrc
2. 为项目本地指定Ruby版本
全局版本生效不代表项目本地版本同步,在项目根目录执行:
rbenv local 2.7.6
此操作会生成.ruby-version文件,强制该项目使用指定版本。
3. 重新绑定bundler到当前Ruby版本
执行以下命令确保bundler关联正确的Ruby版本:
gem install bundler
4. 清理旧版本依赖缓存
删除项目根目录下的Gemfile.lock文件,再重新执行:
bundle install
5. 检查终端路径优先级
执行命令查看Ruby路径:
which ruby
正常输出应为~/.rbenv/shims/ruby,若显示/usr/bin/ruby,说明系统Ruby优先级更高。需确保.zshrc中rbenv的PATH配置在其他PATH设置之前:
export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)"
6. 验证Xcode终端环境的Ruby版本
若通过Xcode内置终端执行命令,需确认其加载了rbenv配置:
rbenv versions
确保2.7.6已列出并设置为默认版本。
内容的提问来源于stack exchange,提问作者BraveEvidence
相关产品推荐
相关产品推荐

