更换和重置Mac Homebrew的默认源

Homebrew作为Mac os系统的包管理器,给软件的安装和更新等带来了极大地便利,但使用过程中总会遇到软件下载特别慢的问题,通过将默认源更改为国内的镜像地址,可以极大地提高下载速度。下面是收集的一些最新的更改默认源的操作(在终端里执行代码):

更换brew.git


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

  更换核心软件仓库(homebrew-core.git)


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

  更换Home Bottles源


1
2
3
4
5
6
长期更换:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

临时更换:
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles 

  更换brew.git


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

  更换核心软件仓库(homebrew-core.git)


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

  更换Home cask软件仓库


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

  更换Home Bottles源


1
2
3
4
5
6
长期更换:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

临时更换:
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles 

  重置brew.git


1
2
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git 

  重置核心软件仓库


1
2
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git 

  重置Homebrew cask软件仓库


1
2
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
git remote set-url origin https://github.com/Homebrew/homebrew-cask 

  重置Homebrew Bottles源


  注释掉bash配置文件里的有关Homebrew Bottles即可恢复官方源。 重启bash或让bash重读配置文件。

  清华Homebrew 镜像使用帮助
中科大Homebrew 源使用帮助