brew update更新速度慢,通过修改镜像源提高下载速度

brew update更新速度慢,通过修改镜像源提高下载速度
最近在Mac上执行brew update命令时速度巨慢,为什么呢?原来brew的默认下载源为Github,由于众所周知的原因,从Github上下载东西速度堪忧啊,我们需要考虑下其它方式:修改镜像源,如:清华、中科大的homebrew镜像源,将下载源切换到国内,下载速度能快不少。

查看默认源地址

首先我们查看默认的源地址:

$ cd "$(brew --repo)"
/usr/local/Homebrew(stable) $ git remote -v 
输出如下内容:
origin    https://github.com/Homebrew/brew (fetch)
origin    https://github.com/Homebrew/brew (push)

$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core(master) $ git remote -v
输出如下内容:
origin    https://github.com/Homebrew/homebrew-core (fetch)
origin    https://github.com/Homebrew/homebrew-core (push)

修改源地址

方式一:替换为清华的brew源

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

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

$ brew update

方式二:替换为中科大的brew源

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

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

$ brew update

还原默认源地址

如果想换回默认源,可以执行如下命令重置回官方默认源:

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

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

$ brew update

参考资料
https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
http://mirrors.ustc.edu.cn/help/brew.git.html

the end

热门文章