You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行brew update提示无法连接github.com超时报错问题求助

brew update连接GitHub超时拉取失败修复方案

执行brew update时出现如下报错:

bhupendra@Bhupendras-MBP mobile-app % brew update                                        
fatal: unable to connect to github.com:
github.com[0: 140.82.121.3]: errno=Operation timed out
fatal: unable to connect to github.com:
github.com[0: 140.82.121.3]: errno=Operation timed out

Error: Fetching /usr/local/Homebrew failed!

Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core failed!

该问题为本地网络无法正常连通GitHub导致,按以下方案操作即可修复:


方案1:替换国内镜像源(优先选择,稳定性最高)

依次执行以下命令替换Homebrew相关仓库的远程地址为国内镜像,全程不需要代理:

  1. 替换Homebrew核心仓库地址
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
  1. 替换homebrew-core仓库地址
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
  1. 若已安装homebrew-cask,额外执行以下命令替换cask源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

所有源替换完成后,直接重新执行brew update即可正常完成更新。
如果后续需要切回官方源,将上述命令中的镜像地址替换为对应GitHub官方仓库地址即可。


方案2:配置Git走本地代理(适合有可用本地代理的场景)

如果本地运行有代理工具,检查并配置Git的代理规则:

  1. 先查询当前Git的全局代理配置
git config --global --get http.proxy
git config --global --get https.proxy
  1. 若查询结果为空,或端口与本地代理的HTTP监听端口不匹配,执行以下命令设置代理,将命令中的端口号替换为你本地代理实际使用的端口(常见端口为7890、1087、8080等)
git config --global http.proxy http://127.0.0.1:替换为你的代理端口
git config --global https.proxy http://127.0.0.1:替换为你的代理端口
  1. 配置完成后先执行curl -I https://github.com测试连通性,返回200状态码后再执行brew update。
    如果后续不需要走代理,执行git config --global --unset http.proxy && git config --global --unset https.proxy即可清除代理配置。

方案3:重置本地Homebrew仓库(适配本地仓库损坏的场景)

如果网络配置无问题但仍拉取失败,大概率是本地仓库文件损坏,执行以下命令重置即可:

注意:M系列芯片Mac的Homebrew默认安装路径为/opt/homebrew,Intel芯片为/usr/local/Homebrew,执行命令时注意替换路径

# Intel芯片执行以下路径
cd /usr/local/Homebrew
# M系列芯片把上面一行替换为 cd /opt/homebrew

git fetch --all
git reset --hard origin/master
brew update

内容的提问来源于stack exchange,提问作者Bhupendra Singh Rautela

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.02 05:18:25