国内镜像安装 homebrew 以及遇到的错误提示

macOS 安装 homebrew 国内的使用者有两个错误比较常见:

error: RPC failed; curl 28 Failed to connect to github.com port 443 after 75000 ms: Couldn't connect to server
fatal: expected flush after ref listing
Warning: Trying again in 2 seconds: /usr/bin/git fetch --quiet --progress --force origin
error: RPC failed; curl 28 Failed to connect to github.com port 443 after 75000 ms: Couldn't connect to server
fatal: expected flush after ref listing

macOS 安装 homebrew 提示:Failed to connect to raw.githubusercontent.com port 443 after 27 ms 错误解决路径-CSDN博客

国内镜像安装是比较稳妥的方式,可选择镜像源主要有三个:

// 清华大学
Tsinghua University: https://mirrors.tuna.tsinghua.edu.cn

// 中科大
USTC (University of Science and Technology of China): https://mirrors.ustc.edu.cn

// 阿里云
Alibaba Cloud: https://mirrors.aliyun.com

以下以清华大学为例,介绍安装过程

第一步

需要准备 

对于 macOS 用户,系统自带 bash、gitcurl,在命令行输入 xcode-select --install 安装 CLT for Xcode 即可。

第二步

设置环境变量(临时)

export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_INSTALL_FROM_API=1

第三步

安装(默认)

git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
/bin/bash brew-install/install.sh

有环境的情况下,直接用 GitHub 下载

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

第四步

删除 brew 安装文件,也可以不操作

rm -rf brew-install

安装过程提示

==> /usr/bin/sudo /bin/mkdir -p /etc/paths.d
==> /usr/bin/sudo tee /etc/paths.d/homebrew
/opt/homebrew/bin
==> /usr/bin/sudo /usr/sbin/chown root:wheel /etc/paths.d/homebrew
==> /usr/bin/sudo /bin/chmod a+r /etc/paths.d/homebrew
HOMEBREW_BREW_GIT_REMOTE set: using https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git as the Homebrew/brew Git remote.

==> Downloading https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:20fa657858e44a4b39171d6e4111f8a9716eb62a78ebbd1491d94f90bb7b830a
########################################################################################### 100.0%
==> Pouring portable-ruby-3.4.5.arm64_big_sur.bottle.tar.gz
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run these commands in your terminal to add Homebrew to your PATH:
    echo >> /Users/username/.zprofile
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/username/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run these commands in your terminal to add the non-default Git remotes for Homebrew/brew and Homebrew/homebrew-core:
    echo '# Set non-default Git remotes for Homebrew/brew and Homebrew/homebrew-core.' >> /Users/username/.zprofile
    echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> /Users/username/.zprofile
    echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> /Users/username/.zprofile
    export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
    export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

对仓库的配置,参考清华的源

homebrew | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

编辑 

vim ~/.bash_profile  

可见配置信息。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值