在使用 Homebrew install的過程中,經常會卡在Updating Homebrew...
這個過程中,下面給出幾種常用的解決辦法:
解決辦法一:修改配置文件,永久取消檢查更新的操作
不推薦此方法,Homebrew庫建議開啓更新。
vim ~/.zshrc
# 新增一行
export HOMEBREW_NO_AUTO_UPDATE=true
解決辦法二:本次取消檢查更新的操作
更新時按住 control + c 之後取消。
brew install composer
Updating Homebrew...
^C
按住 control + c 之後命令行會顯示 ^C,就代表已經取消了 Updating Homebrew 操作
然後就會去執行我們真正需要的安裝操作了
~ brew install nginx
Updating Homebrew...
^C==> Installing dependencies for nginx: pcre
==> Installing nginx dependency: pcre
......
解決辦法三:替換鏡像源(推薦)
平時我們執行 brew 命令安裝軟件的時候,跟以下 3 個倉庫地址有關:
brew.git
homebrew-core.git
homebrew-bottles
通過以下代碼依次將這三個倉庫的鏡像源更換爲不同的國內鏡像源(zsh
下)
1. 官方鏡像源
# 替換brew.git:
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
# 替換homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
# 替換homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
# 應用生效
brew update
# 刪除homebrew-bottles
vi ~/.zshrc
#### 按i進入輸入模式,輸入模式下刪除 HOMEBREW_BOTTLE_DOMAIN 這一行配置,然後按:wq保存並退出
source ~/.zshrc
2. 阿里鏡像源
# 替換brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 替換homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 應用生效
brew update
# 替換homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
3. 清華鏡像源
# 替換brew.git:
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替換homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# 替換homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
# 應用生效
brew update
# 替換homebrew-bottles(根據鏡像地址猜測):
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
4. 中科大鏡像源
# 替換brew.git:
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 替換homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 替換homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# 應用生效
brew update
# 替換homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
以上配置中關於homebrew-bottles
,分爲以下兩種情況:
【1】bash
用戶和zsh
用戶的命令不同,以上示例中關於homebrew-bottles
的替換僅適用於zsh
用戶。
【2】bash
用戶請將配置文件zshrc
換爲bash_profile
下面給出清華大學鏡像源給出的替換homebrew-bottles
在bash
下的代碼,其他以此類推。
### 臨時替換
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
### 長期替換
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile