Fix the slow installation of HomeBrew on Mac. The following

The installation

Install Homebrew on the official website

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Copy the code

Domestic Mirror installation

Obtaining the install file

Access to website and save the script called brew_install:raw.githubusercontent.com/Homebrew/in…

Replace it with a mirror image of Tsinghua University

Open the brew_install file and modify as follows:

Find the following code:

BREW_REPO = "https://github.com/Homebrew/brew". Freeze CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core". FreezeCopy the code

Changed to:

BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git". Freeze CORE_TAP_REPO = "Https://mirrors.ustc.edu.cn/homebrew-core.git". FreezeCopy the code

Note: new versions of HomeBrew may not have the CORE_TAP_REPO code. If not, do not add it. If there is a problem with this image, you can switch to another source.

Execute the script

Open terminal permit script

/usr/bin/ruby brew_install
Copy the code

If the script should stop at this point

==> Tapping homebrew/core

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

This reason is because the source is impassable, the code can not come down, the solution is to replace the domestic mirror source:

Manually execute the following command to replace the cas image:

git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
Copy the code

Then the mirror address of HomeBREW-Core is also set as the domestic mirror address of CAS

cd "$(brew --repo)"

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

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

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

Update succeeded:

brew update
Copy the code

Finally check for errors with this command:

brew doctor
Copy the code

HomeBrew is now installed.

Change the default source

Using Homebrew directly also requires changing the default source. Here’s how to replace the default source with a domestic USTC source. As follows:

Replace the core software repository

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
Copy the code

Replace casK software Repository (macOS applications and large binaries)

cd "$(brew --repo)"/Library/Taps/caskroom/homebrew-cask
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
Copy the code

Replace Bottles (Homebrew pre-compiled binary software package)

Bash (default shell) user:

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

ZSH users:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
Copy the code

Brew Common commands