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

M1 Mac安装Homebrew卡在Receiving objects 4%,求解决方案

Homebrew安装卡在Receiving objects 4%(M1 Mac)

我使用以下命令在M1 Mac上安装Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

但进程始终卡在Receiving objects的4%阶段,日志片段如下:

......
==> /usr/bin/sudo /bin/chmod go-w /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions
==> /usr/bin/sudo /usr/sbin/chown wen.yan /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
==> /usr/bin/sudo /usr/bin/chgrp admin /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
==> /usr/bin/sudo /usr/sbin/chown -R wen.yan:admin /opt/homebrew
==> Downloading and installing Homebrew...
remote: Enumerating objects: 220323, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (47/47), done.
Receiving objects:   4% (8813/220323), 3.78 MiB | 1.79 MiB/s

我已安装Xcode Command Line Tools,且多次重启设备,但问题仍未解决,求可行的解决思路。


解决思路
  • 切换国内镜像源安装
    网络访问GitHub受限是这类问题的核心原因,使用国内镜像脚本可快速解决:

    /bin/bash -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
    

    脚本会引导选择合适的国内源,安装完成后自动配置镜像,避免后续包拉取的网络问题。

  • 手动克隆Homebrew仓库

    1. 终止当前安装进程,清理已生成的目录:
      sudo rm -rf /opt/homebrew
      
    2. 克隆国内镜像的brew核心仓库:
      git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git /opt/homebrew
      
    3. 克隆homebrew-core仓库:
      mkdir -p /opt/homebrew/Library/Taps/homebrew/homebrew-core
      git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git /opt/homebrew/Library/Taps/homebrew/homebrew-core
      
    4. 配置shell环境变量(以zsh为例):
      echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
      eval "$(/opt/homebrew/bin/brew shellenv)"
      
    5. 执行初始化:
      brew update
      
  • 排查网络与DNS配置

    • 切换网络环境(如Wi-Fi换手机热点),排除本地网络的GitHub访问限制。
    • 修改DNS为公共服务地址(如8.8.8.8或114.114.114.114),在「系统设置-网络-高级-DNS」中添加并置顶。
  • 清理Git缓存后重试官方安装
    清除Git的代理缓存,避免残留的连接配置干扰:

    git config --global --unset http.proxy
    git config --global --unset https.proxy
    rm -rf ~/.gitconfig
    

    之后重新运行官方安装命令。


内容的提问来源于stack exchange,提问作者Laodao

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 17:55:30