1. 程式人生 > >替換Mac的home brew源

替換Mac的home brew源

mac預設的homebrew源託管與github,其在國內不好訪問。所以很多同學發現update brew時候常常失敗。

解決方法就是替換brew的源。實際操作中,有4個源需要替換。(這裡用的是中科大的源,其他也有不錯的,比如清華的,大家可以自行搜尋)

1、替換homebrew預設源。

cd "$(brew --repo)"

git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

2、替換homebrew-core預設源

預設是https://github.com/Homebrew/homebrew-core.git, 替換:

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"

git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

3、替換homebrew-cask預設源

cd /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask

git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-cask.git

4、替換homebrew bottles

實際就是修改環境變數。我的mac預設是沒有這個變數的,目前我也沒用到homebrew bottle,不過看其他資料有宣告這個變數的,方法是

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile

source  ~/.bash_profile

如果想恢復官方源,只需要把以上4步反向操作。當然在替換時候也可以使用git remote set-url --add origin <addr>這樣會另新增一個源,原來的源也會保留,具體我們可以通過git config -e看配置檔案.