通过Homebrew安装Cocoapods遇到的一些问题记录

最近遇到无法安装Homebrew的情况

查了一下相关资料,发现阿里云镜像好像用不了了

换成清华大学镜像即可

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

进入安装步骤后,千万不要选择推荐的阿里云镜像


请输入序号: 2
不要选择阿里巴巴国内源,选择清华源

环境变量写入->/Users/terry/.zprofile

安装成功 重启终端即可

如果不小心选择了阿里云,需要卸载 Homebrew后重新安装

1.官方卸载脚本

curl -fsSL -o uninstall.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh

2.执行卸载

分别执行下面代码
chmod +x uninstall.sh
./uninstall.sh

重新安装脚本


/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

如果zsh不行,换成bash


/bin/bash -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

扩展

Bash: 注重兼容性

设计目标:保持与sh兼容,适合脚本编写

/bin/bash -c "echo Hello from Bash"

Zsh: 注重用户体验和功能

设计目标:交互式使用体验好,功能丰富

/bin/zsh -c "echo Hello from Zsh"

扩展:删除Cocoapods 已经安装的项目

步骤1 删除Pods目录和锁定文件


rm -rf Pods/
rm -f Podfile.lock
rm -rf YourProject.xcworkspace
最后 pod cache clean --all

步骤 2:在Xcode中清理项目设置(关键!)

在Finder中,直接双击打开你的 .xcodeproj 项目文件(注意:不是 .xcworkspace)。

在Xcode左侧的项目导航器中,找到并删除名为 Pods 的虚拟文件夹(如果存在)。右键点击它,选择 Delete -> Move to Trash。

点击项目导航器顶部的项目根(蓝色图标),进入项目设置:

切换到 Build Phases 标签页。

找到名为 [CP] Embed Pods Frameworks、[CP] Copy Pods Resources 或类似名称的脚本阶段,逐一删除。

在 Link Binary With Libraries 区域,检查并删除所有以 .framework 结尾的库文件(如 Pods_YourProject.framework 或 Alamofire.framework)。

切换到 Build Settings 标签页:

在顶部的搜索框中输入 Other Linker Flags。

在结果中,找到 Other Linker Flags 这一行,双击其值,在弹出的列表中删除所有以 -l"Pods 或 $(inherited) 开头的条目(通常与Pods相关)。如果不太确定,可以暂时保留 $(inherited),只删除明确的Pods条目。

步骤 3:重启Xcode