mac电脑安装cocoapods出错,以及安装最新版本ruby方法

macbook安装cocoapods时碰到一个报错:大概率是ruby的版本太低导致的

bash 复制代码
sudo gem install cocoapods
ERROR:  Error installing cocoapods:
ERROR: Failed to build gem native extension.
...
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

出现这种情况,大概率是我电脑 ruby 的版本太低了,导致不能安装最新的CocoaPods

安装flutter的环境参考官方文档:Start building Flutter native desktop apps on macOS - Flutter 中文文档 - Flutter 中文开发者网站 - Flutter

那不安装最新 CocoaPods ,指定一个低版本是否可行呢?参考 Mac Flutter环境配置 --- CocoaPods not installed解决方案

复制代码
sudo gem install cocoapods -v 1.8.4

使用如上命令确实安装成功了,但在 Flutter 中启动 Xcode 就会报错,启动失败。

复制代码
Warning: CocoaPods minimum required version 1.9.0 or greater not installed. Skipping pod install.

根据以上,提醒我们需要一个至少 1.9 版本的 CocoaPods,那我卸载然后继续安装 1.9 版本是否就可以了呢?

复制代码
# 卸载
sudo gem uninstall cocoapods

sudo gem install cocoapods -v 1.9.4

我尝试后,发现又安装失败。所以现在的情况就只有一个办法,升级 ruby

使用 homebrew 安装新版本 ruby:

bash 复制代码
brew install ruby

会在安装完后提示两个路径:将这两个路径复制到你的命令行,重新执行一下

复制代码

我们配置新安装ruby的环境变量,不用多想,按照提示来(不要复制如下路径,复制你终端提示的命令)

bash 复制代码
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/**/.bash_profile

export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"

export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"

source /Users/**/.bash_profile

就可以看到版本最新了:

再安装 cocoapods,如果之前有安装记得先卸载(卸载命令上面有):

bash 复制代码
# 卸载
sudo gem uninstall cocoapods

# 安装
sudo gem install cocoapods

就会提示安装成功了:

如果上面安装后运行项目还提醒没有安装 cocoapods not installing,那就这样做:

bash 复制代码
sudo gem uninstall cocoapods
sudo gem install -n /usr/local/bin cocoapods
相关推荐
00后程序员张2 小时前
使用Instruments工具深入分析iOS应用性能与启动时间优化
android·macos·ios·小程序·uni-app·cocoa·iphone
2601_960906723 小时前
AI研发加速中式及泛亚洲
人工智能·vscode·macos·sublime text·phpstorm
sg_knight3 小时前
Codex CLI 安装全攻略:macOS / Linux / Windows(WSL2)三端实战
linux·windows·macos·openai·ai编程·coding·codex
Teleger1 天前
蓝牙 MAC 扫描匹配器
macos
刘婉晴1 天前
【漏扫工具篇】Mac 系统上 Xray 的安装与使用
macos
寒水馨2 天前
macOS下载、安装PowerShell-v7.6.4(附安装包powershell-7.6.4-osx-arm64.pkg)
macos·自动化·跨平台·shell·脚本·命令行·powershell
星辰即远方3 天前
天气预报总结
macos·ios·objective-c·cocoa
xixiaoyunya3 天前
Mac远程访问新范式:基于80KM穿云箭的内网穿透技术实践
macos
秋雨梧桐叶落莳3 天前
计算器仿写总结
学习·macos·ios·objective-c·cocoa
寒水馨3 天前
macOS下载、安装uv-0.12.0(附安装包uv-aarch64-apple-darwin.tar.gz)
python·macos·rust·项目管理·包管理器·astral·pip替代