Apple M2 MacBook Pro安装HomeBrew失败求助
解决Homebrew安装时curl连接raw.githubusercontent.com超时问题(M2 MacBook Pro,macOS Ventura 13.1)
问题概况
- 设备:Apple M2 MacBook Pro(16GB内存/256GB固态硬盘)
- 系统环境:macOS Ventura 13.1,Xcode 14.2,Xcode命令行工具14.2
- 操作流程:
- 下载并安装Xcode 14.2
- 安装Command Line Tools for Xcode 14.2
- 执行Homebrew官方安装命令:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- 错误信息:
curl: (28) Failed to connect to raw.githubusercontent.com port 443 after 75223 ms: Operation timed out
该问题导致无法继续安装CocoaPods。
解决方案
1. 使用国内镜像源安装Homebrew
直接替换官方安装源为国内镜像,执行以下命令:
/bin/bash -c "$(curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git)"
安装完成后,配置Homebrew的国内镜像仓库,避免后续操作再次超时:
# 替换brew.git源 git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git # 替换homebrew-core.git源 git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git # 替换homebrew-cask.git源(如需安装GUI应用,执行此命令) git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git # 更新Homebrew brew update
2. 修改hosts文件强制解析域名
通过修改本地hosts文件指定raw.githubusercontent.com的IP地址,绕开DNS解析问题:
- 打开终端,编辑hosts文件:
sudo nano /etc/hosts
- 在文件末尾添加一行(可通过网络查询该域名的最新可用IP,示例IP如下):
185.199.108.133 raw.githubusercontent.com
- 按
Ctrl+O保存修改,按Ctrl+X退出编辑界面 - 刷新DNS缓存:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
完成后重新执行Homebrew官方安装命令即可。
3. 检查网络代理设置
如果当前开启了代理服务,尝试关闭代理或切换至全局代理模式,确保终端进程能正常通过代理访问外部网络。
验证与后续操作
安装完成后,执行brew -v确认Homebrew安装成功,随后可正常安装CocoaPods:
brew install cocoapods
内容的提问来源于stack exchange,提问作者WeCan
相关产品推荐
相关产品推荐

