一路磕磕绊绊解决flutter doctor 报错CocoaPods not installed

flutter doctor执行之后,出现以下错误:

错误消息:

shell 复制代码
    ✗ CocoaPods not installed.
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      For installation instructions, see
      https://guides.cocoapods.org/using/getting-started.html#installation

解决方案:flutter官网参考: https://docs.flutter.dev/get-started/install/macos/mobile-ios#install-cocoapods

安装命令:

shell 复制代码
# 查看安装进度,在最后加上-V
sudo gem install cocoapods -V 

等了N分钟,再次报错。


错误消息:

shell 复制代码
ERROR:  Error installing cocoapods:
	The last version of securerandom (>= 0.3) to support your Ruby & RubyGems was 0.3.2. Try installing it with `gem install securerandom -v 0.3.2` and then running the current command again
	securerandom requires Ruby version >= 3.1.0. The current ruby version is 2.6.10.210.

提示Ruby版本低了,升级Ruby版本。

网上方案很多,这里采用rvm版本管理的方式进行修复。更多工具参考

rvm安装参考:https://rvm.io/

执行命令:

shell 复制代码
\curl -sSL https://get.rvm.io | bash -s stable

又又报错了!


错误消息:curl: (7) Failed to connect to raw.githubusercontent.com port 443 after 14 ms: Couldn't connect to server

解决方案:

  1. 打开网站,https://www.ipaddress.com/,在此网站中查询一下 raw.githubusercontent.com对应的IP 地址
  1. 配置hosts文件
shell 复制代码
185.199.108.133 raw.githubusercontent.com

再去执行:

shell 复制代码
\curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc',
but no GPG software exists to validate it, skipping.
Installing RVM to /Users/xxx/.rvm/
    Adding rvm PATH line to /Users/xxx/.profile /Users/xxx/.mkshrc /Users/xxx/.bashrc /Users/xxx/.zshrc.
    Adding rvm loading line to /Users/xxx/.profile /Users/xxx/.bash_profile /Users/xxx/.zlogin.
Installation of RVM in /Users/xxx/.rvm/ is almost complete:

  * To start using RVM you need to run `source /Users/yangdong/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
Thanks for installing RVM 🙏
Please consider donating to our open collective to help us maintain RVM.

提示还需执行:

shell 复制代码
source /Users/xxx/.rvm/scripts/rvm

才能生效。

查看是否安装成功:

shell 复制代码
rvm --version
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

使用rvm安装Ruby:

shell 复制代码
rvm install "ruby-3.4.3"

下载有点慢~

我丢,又特么报错了!

shell 复制代码
ruby-3.4.3 - #extracting ruby-3.4.3 to /Users/xxxx/.rvm/src/ruby-3.4.3 - please wait
ruby-3.4.3 - #configuring - please wait
ruby-3.4.3 - #post-configuration - please wait
ruby-3.4.3 - #compiling - please wait
Error running '__rvm_make -j10',
please read /Users/xxx/.rvm/log/1744902490_ruby-3.4.3/make.log

There has been an error while running make. Halting the installation.

查看报错:

shell 复制代码
cat /Users/xxx/.rvm/log/1744902490_ruby-3.4.3/make.log

具体报错信息:

shell 复制代码
./openssl_missing.h:195:11: warning: 'TS_VERIFY_CTS_set_certs' macro redefined [-Wmacro-redefined]
  195 | #  define TS_VERIFY_CTS_set_certs(ctx, crts) ((ctx)->certs=(crts))
      |           ^
/opt/homebrew/Cellar/openssl@3/3.4.1/include/openssl/ts.h:439:11: note: previous definition is here
  439 | #  define TS_VERIFY_CTS_set_certs(ctx, cert) TS_VERIFY_CTX_set_certs(ctx,cert)
      |           ^

查资料大概意思:

报错是发生在openssl@3,大概原因应该就是安装Ruby的时候需要编译用到openssl, 但是没有指定openssl路径的情况下,它就会默认到/usr/local/Cellar下的openssl使用,但是正常使用brew 更新或者安装过openssl的话路径并不在这里,应该在/usr/local/opt/openssl@3或者/opt/homebrew/Cellar/openssl@3 这里,具体位置报错信息有提示。这也就是导致编译的时候openssl的某些方法找不到等等错误。

解决方案:

shell 复制代码
rvm install 3.4.3 --with-openssl-dir=`brew --prefix openssl` | rvm install 3.4.3 --with-openssl-dir='/opt/homebrew/Cellar/openssl@3'

等半天~

shell 复制代码
Install of ruby-3.4.3 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri

终于成功了!

查看Ruby版本:

shell 复制代码
ruby --version
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [arm64-darwin24]

再次执行sudo gem install cocoapods -V

尼玛,又报错了~

具体报错信息:

shell 复制代码
 OpenSSL is not available. Install OpenSSL and rebuild Ruby or use non-HTTPS sources (Gem::Exception)

解决方案:

shell 复制代码
rvm reinstall 3.4.3 --with-openssl-dir=`brew --prefix openssl`

再去执行:sudo gem install cocoapods -V

终于可以了~~~耐心等待中!

shell 复制代码
Successfully installed cocoapods-1.16.2
34 gems installed

啥也不说了,特么终于安装上了!!!

再次执行flutter doctor

输出信息:

shell 复制代码
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.29.3, on macOS 15.4 24E248 darwin-arm64, locale zh-Hans-001)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.6)
[✓] VS Code (version 1.98.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

其中艰辛,只有两个字含泪~~~

相关推荐
SoaringHeart39 分钟前
Flutter最佳实践:用 flutter_html 渲染富文本
前端·flutter
恋猫de小郭14 小时前
Flutter 3.50.0 Release 的第一个崩溃,修好了,还没 hotfix
android·前端·flutter
程序员老刘1 天前
跨平台开发地图 | 2026年11月
flutter·ai编程·客户端
传奇开心果编程2 天前
【Flutter踩坑排雷】第30课:异常未捕获坑|未捕获异常直接闪退,全局兜底故障处理
android·flutter·ios·移动开发·dart·ui框架·声明式ui
恋猫de小郭2 天前
Flutter Native Interop 稳定了,Platform Channel 要退场了
android·前端·flutter
好的佩奇2 天前
Dart 之可迭代对象与生成器
android·flutter·dart
恋猫de小郭3 天前
Flutter Analyzer 系列坑推进,必看,AI 时代这玩意最吃你内存
android·前端·flutter
LinXunFeng3 天前
拿竞品 App 一扫,技术栈全暴露了
android·flutter·开源
传奇开心果编程4 天前
【Flutter踩坑排雷】第28课:平台目录缺失与修复坑|`flutter create` 的“重建”与“覆盖”边界
android·flutter·ios·移动开发·跨平台·dart·声明式ui
程序员老刘·4 天前
Flutter 3.50更新,开发者应该关注什么?
flutter·ai编程·跨平台开发