Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”
Updating Homebrew may get stuck in the Updating Homebrew step for a long time in a domestic network environment.
Example: Run the brew install composer command
➜ ~ brew install composer Updating Homebrew... # If you encounter a long time stuck here, refer to the following 2 treatment methodsCopy the code
Method 1: Hold down Control + C to cancel the update
➜ ~ brew install composer
Updating Homebrew...
^C
Copy the code
Pressing Control + C will show ^ con the command line, indicating that the Updating Homebrew operation has been cancelled
It will take less than a second to perform the installation we really need
➜ ~ brew install composer Updating Homebrew... ^ C = = > Satisfying dependencies = = > Downloading https://getcomposer.org/download/1.7.2/composer.phar...Copy the code
This approach is temporary and one-time
Method 2: Use Alibaba’s Homebrew mirror source for acceleration
Usually, when we execute brew command to install software, it is related to the following three warehouse addresses:
- brew.git
- homebrew-core.git
- homebrew-bottles
Replace all the three warehouse addresses with those provided by Alibaba through the following operations
1. Replace/restore the brew.git repository address
#Replace with alibaba's brew.git repository address:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
#Restore to the official brew.git repository address
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
Copy the code
2. Replace/restore the homebrew-core-git repository address
#Replace with alibaba homebrew-core-git repository 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 repository address
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git
Copy the code
3. Replace/restore homebrew-BOTTLES access address
This step depends on the shell version of your macOS system
So, first look at the shell version you’re currently using
echo $SHELL
#If your output is /bin/zsh, see? ZSH terminal operation mode
#If your output is /bin/bash, see? Bash terminal operation mode
Copy the code
3.1 ZSH Terminal Operation Modes
#Replace into Alibaba homebrew-bottles.
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
#Restore the official homebrew-BOTTLES access address
vi ~/.zshrc
#Then, delete the HOMEBREW_BOTTLE_DOMAIN configuration
source ~/.zshrc
Copy the code
3.2 Bash Terminal Operation Mode
#Replace Homebrew-bottles!
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
#= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
#Restore the official homebrew-BOTTLES access address
vi ~/.bash_profile
#Then, delete the HOMEBREW_BOTTLE_DOMAIN configuration
source ~/.bash_profile
Copy the code
HomeBrew is quick to install
Automatic script (all domestic addresses) (Copy and paste the following sentence in Mac OS terminal)
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
Copy the code