本地初始化React Native项目遇Bundler安装失败及环境问题
React Native 项目初始化失败解决方案
问题根源
导致初始化失败的两个关键问题:
- RubyGems版本(3.0.3.1)存在bug,且当前Ruby版本(2.6.10)不满足Gemfile指定的2.7.6版本要求
- iOS开发环境未完成正确配置
一、修复Ruby与RubyGems版本
- 升级RubyGems到指定版本
执行以下命令:gem update --system 3.2.3 - 安装/切换到Ruby 2.7.6版本
推荐使用版本管理工具(如rbenv或rvm)来管理Ruby版本:- 使用rbenv的操作:
rbenv install 2.7.6 rbenv local 2.7.6 # 仅当前项目生效,或用global设置全局版本 - 使用rvm的操作:
rvm install 2.7.6 rvm use 2.7.6 --default
- 使用rbenv的操作:
- 重新安装Bundler
版本适配后安装Bundler:gem install bundler
二、配置iOS开发环境
完成以下必要配置:
- 安装Xcode,并确保安装了Command Line Tools(可通过Xcode偏好设置 → Locations 标签页安装)
- 安装CocoaPods:
sudo gem install cocoapods - 验证并设置Xcode命令行工具路径:
若路径错误,执行:xcode-select --print-pathsudo xcode-select -s /Applications/Xcode.app/Contents/Developer - 接受Xcode许可协议:
sudo xcodebuild -license accept
三、重新初始化项目
完成所有配置后,重新执行初始化命令:
npx react-native init notexpoapp3 --template react-native-template-typescript
内容的提问来源于stack exchange,提问作者kyrolos magdy
相关产品推荐
相关产品推荐

