M1 Mac安装Homebrew时卡在XCode Command Line Tools安装环节
问题背景
首次使用Homebrew时遭遇错误:
zsh: command not found: brew
尝试过将/opt/homebrew/bin/加入PATH、在~/.zshrc中添加export PATH="$PATH:/opt/homebrew/bin/"均无效,删除/opt/homebrew文件夹后执行官方安装脚本:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
但安装卡在XCode Command Line Tools环节,超时后提示:
Timed out while loading data from the Apple Software Update server.
==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
Password:
==> Installing the Command Line Tools (expect a GUI popup):
==> /usr/bin/sudo /usr/bin/xcode-select --install
xcode-select: note: install requested for command line developer tools
Press any key when the installation has completed.
手动安装XCode Command Line Tools也未成功,需解决Homebrew安装障碍以开展开发工作。
解决步骤
1. 手动安装XCode Command Line Tools
- 打开系统设置 → 通用 → 软件更新,检查是否有Command Line Tools的更新提示,直接完成安装。
- 若系统更新无相关提示,在终端执行:
此时会弹出GUI安装窗口,若弹出后卡住,关闭终端和安装窗口,重复执行命令直到安装流程正常启动。xcode-select --install
2. 确认Command Line Tools路径
安装完成后,执行以下命令验证并指定正确路径:
sudo xcode-select --switch /Library/Developer/CommandLineTools
检查路径是否生效:
xcode-select -p
输出/Library/Developer/CommandLineTools即为配置正确。
3. 重新执行Homebrew安装脚本
确保Command Line Tools安装无误后,再次运行官方安装脚本:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
4. 验证Homebrew安装结果
关闭终端并重新打开,执行:
brew --version
能正常输出版本信息即为安装成功。
5. 修复PATH配置(若之前配置失效)
打开~/.zshrc文件,添加:
export PATH="/opt/homebrew/bin:$PATH"
保存后执行:
source ~/.zshrc
再次验证brew命令是否可正常调用。
内容的提问来源于stack exchange,提问作者Al Chandeck

