homebrew使用清华源

homebrew使用清华源

三月 14, 2020

最近使用homebrew安装软件在update时奇慢无比, 几乎达到不可用状态, 于是找了下国内清华源镜像

替换镜像

按照清华源文档替换源:

# brew 程序本身,Homebrew/Linuxbrew 相同
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

# 以下针对 mac OS 系统上的 Homebrew
$ 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
$ git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
$ git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git

替换后更新发现并没有什么用, 依旧卡住, 输入brew update --verbose查看详细情况

$ brew update --verbose
Checking if we need to fetch /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask...
Fetching /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/caskroom/homebrew-versions...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-fonts...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-fonts...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Fetching /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask...

发现在/usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask 处卡住, 于是进入homebrew-cask目录, 查看git仓库地址:

$ cat /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask/.git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
    autocrlf = false
[remote "origin"]
    url = https://github.com/caskroom/homebrew-cask
    fetch = +refs/heads/master:refs/remotes/origin/master
[branch "master"]
    remote = origin
    merge = refs/heads/master
[homebrew]
    private = false

发现这里地址仍然是github, 输入

$ git remote set-url https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

再次执行brew update 生效