# 设置Homebrew默认源

请根据笔记的写作日期,选择性阅读。

作者: 放羊的大少爷
Home: joynoting.com
系统: Mac@10.14.6
软件版本:
brew@2.1.10
参考:
替换及重置Homebrew默认源


用 brew 的人都知道,默认情况下 Homebrew 由于是国外的服务器,很多时候下载东西网速是很慢的,好在国内提供了相应的镜像源,该文档就教你设置 brew、homebrew-cask 和 homebrew-core。


# 一、中科大源

# 1. 设置为中科大源

# 1.1 替换brew.git:

cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
1
2

#

# 1.2 替换homebrew-cask.git:

cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
1
2

# 1.3 替换homebrew-core.git:

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
1
2

#

# 1.4 设置homebrew-bottles

# 1.4.1 bash用户
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
1
2
# 1.4.2 zsh用户
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
1
2
# 1.4.3 临时替换
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
1

# 2. 重置brew默认源

重新修改 brew.git 和 homebrew-core.git,然后注释掉 bash 或 zsh 配置文件里的有关 Homebrew Bottles 即可恢复官方源,最后使 bash 或让 bash 配置文件生效即可。

# 二、清华源

# 1. 设置为清华源

# 1.1 设置brew.git等

git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
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/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
brew update
1
2
3
4

# 1.2 设置homebrew-bottles

# 1.2.1 bash用户
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
1
2
# 1.2.2 zsh用户
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
1
2
# 1.2.3 临时替换
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
1

# 2. 重置brew默认源

git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
brew update
1
2
3
4

然后注释掉 bash 或 zsh 配置文件里的有关 Homebrew Bottles 即可恢复官方源,最后使 bash 或让 bash 配置文件生效即可。

# 三、常用源

# 3.1 中科大

https://mirrors.ustc.edu.cn/brew.git
https://mirrors.ustc.edu.cn/homebrew-core.git
1
2

# 3.2 清华

https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
1
2
3

# 3.3 官方默认源

https://github.com/Homebrew/brew.git
https://github.com/Homebrew/homebrew-core.git
1
2
上次更新时间: 2020/3/13 下午12:44:00