Solution of long time card in Updating Homebrew by executing brew install command

In the process of using Homebrew to install software in the domestic network environment, it may be stuck in the Updating Homebrew step for a long time.

Example: execute the brew install composer command

➜  ~ brew install composer
Updating Homebrew... # If you are stuck here for a long time, please refer to the following two handling methods

Method 1: press and hold control + c to cancel the update operation

➜  ~ brew install composer
Updating Homebrew...
^C

Hold control + c and the command line will display ^ C, which means the Updating Homebrew operation has been canceled

In less than a second, we'll perform the installation we really need

➜  ~ brew install composer
Updating Homebrew...
^C==> Satisfying dependencies
==> Downloading https://getcomposer.org/download/1.7.2/composer.phar
...

This method is temporary and disposable

Method 2: use Alibaba's Homebrew image source for acceleration

When we execute the brew command to install the software, it is related to the following three warehouse addresses:

  1. brew.git

  2. homebrew-core.git

  3. homebrew-bottles

Replace all three warehouse addresses with the addresses provided by Alibaba by the following operations

1. Replace / restore brew.git warehouse address

# Replace with Alibaba's brew.git warehouse address:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

#=======================================================

# Restore to the official brew.git warehouse address
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

2. Replace / restore homebrew-core.git warehouse address

# Replace with Alibaba's homebrew-core.git warehouse address:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

#=======================================================

# Restore to the official homebrew-core.git warehouse address
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git

3. Replace / restore homebrew robots access address

This step is related to the shell version of your Mac OS system

So, let's first look at the shell version currently in use

echo $SHELL

# If your output is / bin/zsh, refer to the zsh terminal operation mode of
# If your output is / bin/bash, refer to the bash terminal operation mode of

3.1 zsh terminal operation mode

# Replace with Alibaba's homebrew bots address:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

#=======================================================

# Restore to the official homebrew robots access address
vi ~/.zshrc
# Then, delete the configuration in the row "home brew? Bottom? Domain"
source ~/.zshrc

3.2 bash terminal operation mode

# Replace homebrew bots access URL:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

#=======================================================

# Restore to the official homebrew robots access address
vi ~/.bash_profile
# Then, delete the configuration in the row "home brew? Bottom? Domain"
source ~/.bash_profile

Tags: brew git shell github

Posted on Thu, 14 Nov 2019 08:12:10 -0800 by sambkk