国内网络访问 GitHub 不稳定导致的 homebrew 安装失败
2026/8/21 10:40:30 网站建设 项目流程

% /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
==> Checking forsudoaccess (which may request your password)…
Password:
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew
/etc/paths.d/homebrew
Press RETURN/ENTER to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R edy:admin /opt/homebrew
==> Downloading and installing Homebrew…
fatal: unable to access ‘https://github.com/Homebrew/brew/’: Failed to connect to github.com port 443 after 78175 ms: Couldn’t connect to server
Warning: Trying again in 2 seconds: /usr/bin/git fetch --quiet --progress --force origin
fatal: unable to access ‘https://github.com/Homebrew/brew/’: SSL connection timeout
Warning: Trying again in 4 seconds: /usr/bin/git fetch --quiet --progress --force origin
fatal: unable to access ‘https://github.com/Homebrew/brew/’: Could not resolve host: github.com
Warning: Trying again in 8 seconds: /usr/bin/git fetch --quiet --progress --force origin
fatal: unable to access ‘https://github.com/Homebrew/brew/’: Could not resolve host: github.com
Warning: Trying again in 16 seconds: /usr/bin/git fetch --quiet --progress --force origin
remote: Enumerating objects: 355727, done.
remote: Counting objects: 100% (721/721), done.
remote: Compressing objects: 100% (246/246), done.
error: RPC failed; curl 56 Recv failure: Operation timed out
error: 30 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
Failed 5 times doing: /usr/bin/git fetch --quiet --progress --force origin


这是典型的国内网络访问 GitHub 不稳定导致的安装失败。报错中既有 DNS 解析失败,也有 SSL 超时和 RPC 断连,说明直连 GitHub 完全不可靠。

推荐方案:使用清华镜像源安装

在终端依次执行以下命令,先设置镜像环境变量,再运行安装脚本:

# 1. 设置 Homebrew 各组件的国内镜像exportHOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"exportHOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"exportHOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"exportHOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"# 2. 调大 git 缓冲区,避免 RPC 断连gitconfig--globalhttp.postBuffer524288000# 3. 重新运行安装脚本/bin/bash-c"$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

如果连raw.githubusercontent.com都打不开(下载安装脚本本身就失败),改用中科大镜像的安装脚本:

/bin/bash-c"$(curl-fsSLhttps://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"

这个脚本会自动配置国内镜像源。

安装完成后,把镜像配置写入 shell 配置文件,避免以后每次都要手动 export:

# 如果用 zsh(macOS 默认)echo'export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"'>>~/.zshrcecho'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"'>>~/.zshrcecho'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"'>>~/.zshrcecho'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"'>>~/.zshrcsource~/.zshrc

核心思路:安装过程中真正耗时的git fetch从 GitHub 拉取,换成清华/中科大镜像后速度和稳定性都会正常。git postBuffer调大则解决大包传输时的 RPC 断连问题。

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询