update Homebrew 太慢,更換Homebrew的更新源

參考文章:
更新源的選擇
默認官方的更新源都是存放在GitHub上的,這也是中國大陸用戶訪問緩慢的原因,一般來說我們會更傾向選擇國內提供的更新源,在此推薦中國科大以及清華大學提供的更新源。

替換更新源

# 替換brew.git:
$ cd "$(brew --repo)"
# 中國科大:
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 清華大學:
$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

# 替換homebrew-core.git:
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
# 中國科大:
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 清華大學:
$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

# 替換homebrew-bottles:
# 中國科大:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 清華大學:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile

# 應用生效:
$ brew update

如果你之前折騰過不少導致你的Homebrew有點問題,那麼可以嘗試使用如下方案:

# 診斷Homebrew的問題:
$ brew doctor

# 重置brew.git設置:
$ cd "$(brew --repo)"
$ git fetch
$ git reset --hard origin/master

# homebrew-core.git同理:
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
$ git fetch
$ git reset --hard origin/master

# 應用生效:
$ brew update  

重置更新源 某些時候也有換回官方源的需求

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

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

後記
完成更新源的更換後,我們可以使用
$ brew upgrade將現有的軟件進行更新至最新版本,這樣便能很直接的看出速度上的變化了。最後不要忘記$ brew cleanup將舊有的軟件安裝包進行清理
原作鏈接

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章