DesignPatternsPHP:享元模式优化内存使用效率的终极指南
2026/5/6 16:32:29
通过国内Gitee源的卸载脚本完成了Homebrew卸载,但脚本未能完全删除/usr/local/目录下的相关文件,需要手动清理残留。接下来需要重新安装Homebrew并配置国内镜像以加速软件包下载。
/bin/zsh -c"$(curl-fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"已成功删除的目录:
/Users/wangzhenye/Library/Caches/Homebrew/✅/Users/wangzhenye/Library/Logs/Homebrew/✅因权限问题未删除的目录:
/usr/local/Caskroom/❌Permission denied/usr/local/Cellar/❌Permission denied残留的Homebrew相关目录:
/usr/local/Homebrew//usr/local/bin//usr/local/cli-plugins//usr/local/etc//usr/local/lib//usr/local/share//usr/local/var/uname-mx86_64= Intel芯片arm64= Apple Silicon芯片(M1/M2/M3)根据你的芯片类型选择相应命令:
对于Apple Silicon芯片(arm64):
# 使用sudo提升权限删除残留sudorm-rf /opt/homebrewsudorm-rf /usr/local/Homebrewsudorm-rf /usr/local/Caskroomsudorm-rf /usr/local/Cellarsudorm-rf /usr/local/var/homebrew# 清理其他残留sudorm-rf /usr/local/bin/brewsudorm-rf /usr/local/cli-plugins/brewsudorm-rf /usr/local/etc/bash_completion.d/brewsudorm-rf /usr/local/share/doc/homebrewsudorm-rf /usr/local/share/man/man1/brew.1对于Intel芯片(x86_64):
# 主要清理/usr/local/下的残留sudorm-rf /usr/local/Homebrewsudorm-rf /usr/local/Caskroomsudorm-rf /usr/local/Cellarsudorm-rf /usr/local/var/homebrew# 清理brew可执行文件和相关文件sudorm-f /usr/local/bin/brewsudorm-rf /usr/local/cli-plugins/brewsudorm-rf /usr/local/etc/bash_completion.d/brew# 删除用户目录下的缓存和配置rm-rf ~/.homebrewrm-rf ~/Library/Caches/Homebrewrm-rf ~/Library/Logs/Homebrew确保已安装Xcode命令行工具:
xcode-select --install/bin/zsh -c"$(curl-fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"安装过程中会提示:
# 检查版本brew -v# 运行诊断brew doctor# 更新brew自身brew update如果遇到权限错误,可以:
# 检查目录所有权ls-la /usr/local/# 修复权限(谨慎使用)sudochown-R$(whoami)/usr/local/*# 仅当你知道自己在做什么时使用安装后如果brew命令不可用,需要配置环境变量:
对于Zsh用户:
echo'eval "$(/opt/homebrew/bin/brew shellenv)"'>>~/.zshrcsource~/.zshrc对于Bash用户:
echo'eval "$(/opt/homebrew/bin/brew shellenv)"'>>~/.bash_profilesource~/.bash_profile# 替换brew.git镜像cd"$(brew --repo)"gitremote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git# 替换homebrew-core.git镜像cd"$(brew --repo)/Library/Taps/homebrew/homebrew-core"gitremote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git# 更新生效brew update| 问题 | 可能原因 | 解决方案 |
|---|---|---|
brew: command not found | 环境变量未配置 | 按上述"环境变量配置"步骤操作 |
| 权限拒绝错误 | 残留文件所有权问题 | 使用sudo或修复目录所有权 |
| 安装速度慢 | 未使用国内镜像 | 重新运行安装脚本选择国内源 |
| 某些命令不可用 | 未安装Xcode命令行工具 | 运行xcode-select --install |
brew cleanup定期清理旧版本brew leaves > brew_packages.txt备份已安装包列表brew bundle管理软件包依赖~/Library/Logs/Homebrew/下的日志文件通过以上步骤,你应该能完成Homebrew的彻底重装。如果在执行过程中遇到具体错误信息,可以进一步提供详细信息以便针对性解决。