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

React Native iOS项目创建失败,Ruby环境配置问题求助

React Native iOS环境Ruby Bundler安装失败(OpenSSL错误)解决方案

1. 清理无效的RVM环境

如果之前用RVM的操作没解决问题,先彻底移除RVM:

  • 执行卸载命令:rvm implode
  • 删除残留配置文件:rm -rf ~/.rvm ~/.rvmrc /etc/rvmrc
  • 重启终端,输入rvm -v确认RVM已被移除

2. 用Homebrew搭建正确的Ruby环境

RVM的OpenSSL依赖问题容易踩坑,换用rbenv更稳定:

  • 没装Homebrew先装:/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • 安装OpenSSL:brew install openssl
  • 安装rbenv和ruby-build:brew install rbenv ruby-build
  • 把rbenv加入shell配置:
    • Bash用户:echo 'eval "$(rbenv init - bash)"' >> ~/.bash_profile
    • Zsh用户:echo 'eval "$(rbenv init - zsh)"' >> ~/.zshrc
  • 重启终端,输入rbenv -v确认安装成功

3. 安装项目适配的Ruby版本

React Native对Ruby版本有要求,先看项目iOS目录的Gemfile里指定的版本(比如常见的3.2.2):

  • 安装指定版本:rbenv install 3.2.2
  • 进入项目iOS目录,绑定本地Ruby版本:
    cd /path/to/your/test/ios
    rbenv local 3.2.2
    
  • 输入ruby -v确认版本匹配

4. 安装Bundler并拉取依赖

  • 如果项目有Gemfile.lock,安装对应版本的Bundler:gem install bundler:$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)
  • 没有lock文件就装最新兼容版:gem install bundler
  • 执行bundle install安装iOS所需的Ruby依赖

5. 检查Xcode工具和CocoaPods

  • 确保Xcode命令行工具正常:xcode-select --install,如果提示已安装,执行sudo xcode-select --reset重置
  • 用项目的Ruby环境安装CocoaPods依赖:bundle exec pod install

6. 验证项目运行

回到项目根目录,执行npx react-native run-ios测试iOS端是否能正常启动

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 21:17:43