Mac M1(Ventura13.3.1)下CocoaPods已安装但无法使用的Flutter问题
解决Flutter Doctor提示CocoaPods已安装但无法工作的问题
问题描述
执行sudo flutter doctor时持续收到以下错误:
✗ CocoaPods installed but not working.
You appear to have CocoaPods installed but it is not working.
This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
This can usually be fixed by re-installing CocoaPods.
To re-install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
已尝试操作:
- 多次执行
sudo gem install cocoapods重新安装CocoaPods - 尝试过Apple Silicon M1相关的CocoaPods修复方案
- 当前环境:
pod --version为1.12.1,ruby --version为ruby 3.0.0p0
解决方案
1. 彻底卸载现有CocoaPods
先完全清理已安装的CocoaPods及其依赖:
sudo gem uninstall cocoapods sudo gem uninstall cocoapods-core sudo gem uninstall cocoapods-downloader rm -rf ~/.cocoapods
2. 确认Ruby环境路径
检查当前Ruby的安装路径,确保后续安装使用同一环境:
which ruby ruby -e 'puts Gem.user_dir'
3. 无sudo重新安装CocoaPods
避免sudo导致的权限和环境不一致问题,使用用户级gem安装:
gem install cocoapods --user-install
4. 配置环境变量(若需)
如果安装后pod命令无法找到,将Ruby的gem bin目录添加到PATH:
# 针对zsh终端 echo 'export PATH="$HOME/.gem/ruby/3.0.0/bin:$PATH"' >> ~/.zshrc source ~/.zshrc # 针对bash终端 echo 'export PATH="$HOME/.gem/ruby/3.0.0/bin:$PATH"' >> ~/.bash_profile source ~/.bash_profile
5. 初始化CocoaPods仓库
重新设置CocoaPods仓库:
pod setup
6. 验证修复效果
执行以下命令检查Flutter环境:
flutter doctor
备选方案:用Homebrew安装CocoaPods
若上述方法无效,尝试通过Homebrew安装以规避Ruby版本冲突:
brew install cocoapods brew link --overwrite cocoapods
内容的提问来源于stack exchange,提问作者Vinícius Soares
相关产品推荐
相关产品推荐

