1. 程式人生 > 實用技巧 >homebrew 切換國內映象 清華映象

homebrew 切換國內映象 清華映象

首次安裝 Homebrew

首先,下載安裝指令碼的映象(也可以直接從官方下載,即https://raw.githubusercontent.com/Homebrew/install/master/install.sh

git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git
cd install

並編輯其中的install.sh

BREW_REPO="https://github.com/Homebrew/brew"
# 改成:
BREW_REPO="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"

接著,執行install.sh以安裝 Homebrew

出現如下程式碼時,不用等了,直接關掉命令視窗

Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...

進入下面的 Taps 目錄,clone homebrew-core

cd /usr/local/Homebrew/Library/Taps/homebrew

git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

把homebrew repo切換為清華映象

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

這時,終端會顯示Already up-to-date.到此,homebrew就安裝完畢了。