Mac下更換Homebrew源

https://segmentfault.com/a/1190000037439639

默認Homebrew的源會使用Github,國內使用會很慢。可以通過更改爲國內的源,提高訪問速度。

Step 1 先重置一下(原理就是重置一下brew.git和homebrew-core.git)

# 診斷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

Step 2 使用國內的源

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


更新代碼
git fetch --unshallow

# 更新
brew update

Step 3清理舊的安裝包

 brew cleanup

如果想換回官方源使用如下命令

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