Homebrew切换镜像
介绍
当使用Homebrew
安装软件时,默认会从GitHub
下载,速度较慢,可以切换国内镜像来提高下载速度。
默认仓库地址
Homebrew
核心代码仓库:
Homebrew
的核心代码托管在 GitHub
上。默认仓库地址为:
https://github.com/Homebrew/brew.git
公式(Formulae
)仓库:
Homebrew
的包(Formulae
)主要在以下两个仓库中:
Homebrew
核心包:
https://github.com/Homebrew/homebrew-core.git
Homebrew Cask
包(主要是macOS GUI
应用):
https://github.com/Homebrew/homebrew-cask.git
Bottles
下载源:
Bottles
是 Homebrew
用于快速安装的二进制包,默认托管在 GitHub Packages
上。默认地址类似于:
https://ghcr.io/v2/homebrew/core/<package-name>
设置国内镜像
在国内使用 Homebrew
的默认地址可能较慢。可以切换到国内镜像。
切换Bottles
源
要让 bottle 镜像永久生效,把这一行加到 ~/.zprofile
或 ~/.zshrc
中。 编辑~/.zshrc
文件,添加HOMEBREW_BOTTLE_DOMAIN
环境变量,指向国内镜像地址。
$ cd ~
$ vim .zshrc
添加HOMEBREW_BOTTLE_DOMAIN
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
移除HOMEBREW_BOTTLE_DOMAIN
,也可以手动编辑删除。
$ unset HOMEBREW_BOTTLE_DOMAIN
注意 这里使用中科大bottles
源镜像,也可以使用其他的国内镜像,如清华镜像、阿里云镜像等。
核心代码和公式仓库源
切换为指定源:
# 替换 Homebrew 核心
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替换 Homebrew-core
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# 替换 Homebrew-cask
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
查看 Homebrew 主仓库的源地址:
$ git -C "$(brew --repo)" remote -v
origin https://github.com/Homebrew/brew (fetch)
origin https://github.com/Homebrew/brew (push)
换源之后查询
$ git -C "$(brew --repo)" remote -v
origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git (fetch)
origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git (push)
查看 Core 仓库的源地址:
$ git -C "$(brew --repo homebrew/core)" remote -v
fatal: cannot change to '/opt/homebrew/Library/Taps/homebrew/homebrew-core': No such file or directory
$ brew tap homebrew/core
Error: Tapping homebrew/core is no longer typically necessary.
Add --force if you are sure you need it for contributing to Homebrew.
$ brew tap --force homebrew/core
==> Tapping homebrew/core
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 2640416, done.
remote: Counting objects: 100% (63/63), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 2640416 (delta 53), reused 31 (delta 31), pack-reused 2640353 (from 4)
Receiving objects: 100% (2640416/2640416), 914.98 MiB | 1.21 MiB/s, done.
Resolving deltas: 100% (1959537/1959537), done
$ git -C "$(brew --repo homebrew/core)" remote -v
origin https://github.com/Homebrew/homebrew-core (fetch)
origin https://github.com/Homebrew/homebrew-core (push)
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
$ git -C "$(brew --repo homebrew/core)" remote -v
origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git (fetch)
origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git (push)
查看 Cask 仓库的源地址:
$ git -C "$(brew --repo homebrew/cask)" remote -v
fatal: cannot change to '/opt/homebrew/Library/Taps/homebrew/homebrew-cask': No such file or directory
$ brew tap homebrew/cask
Error: Tapping homebrew/cask is no longer typically necessary.
Add --force if you are sure you need it for contributing to Homebrew.
$ brew tap --force homebrew/cask
==> Tapping homebrew/cask
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 1281471, done.
remote: Counting objects: 100% (346/346), done.
remote: Compressing objects: 100% (176/176), done.
remote: Total 1281471 (delta 304), reused 172 (delta 170), pack-reused 1281125 (from 4)
Receiving objects: 100% (1281471/1281471), 441.93 MiB | 1.40 MiB/s, done.
Resolving deltas: 100% (960195/960195), done.
$ git -C "$(brew --repo homebrew/cask)" remote -v
origin https://github.com/Homebrew/homebrew-cask (fetch)
origin https://github.com/Homebrew/homebrew-cask (push)
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
$ git -C "$(brew --repo homebrew/cask)" remote -v
origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git (fetch)
origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git (push)
恢复为默认源:
# 恢复 Homebrew 核心
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
# 恢复 Homebrew-core
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
# 恢复 Homebrew-cask
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
Homebrew
国内镜像
清华开源镜像
核心代码:
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
Formulae
仓库:
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
Cask
仓库:
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
bottles
源:
https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
中科大镜像站
核心代码:
https://mirrors.ustc.edu.cn/homebrew-brew.git
Formulae
仓库:
https://mirrors.ustc.edu.cn/homebrew-core.git
bottles
源:
https://mirrors.ustc.edu.cn/homebrew-bottles