Homebrew relies on Xcode Command Line Tools, so you need to execute:

xcode-select --install
Copy the code

I. Official (GitHub)

Brew. sh/index_zh-cn Official GitHub: github.com/Homebrew

1. Install

# zsh
$ /bin/zsh -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# bash
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Copy the code

2. Check whether the installation is successful

$brew-v Homebrew 2.6.0 Homebrew/ Homebrew-core (Git Revision 5eBB5; last commit 2020-12-09) Homebrew/homebrew-cask (git revision aea32; last commit 2020-11-24)Copy the code

3. Check the Homebrew source

# Check brew sources
$ git -C "$(brew --repo)" remote -v
# Check homebreW-core source
$ git -C "$(brew --repo homebrew/core)" remote -v
# Check homebrew-Cask source
$ git -C "$(brew --repo homebrew/cask)" remote -v

# Homebrew-cask-fonts, homebrew-cask-drivers, etc
$ git -C "$(brew --repo homebrew/cask-fonts)" remote -v
$ git -C "$(brew --repo homebrew/cask-drivers)" remote -v
Copy the code

At this point Homebrew can be used, but the disadvantages of unstable connection and slow download speed in foreign countries can be said to be fatal, which greatly affects efficiency in actual use. The following is to introduce the methods of domestic installation and the method of switching Homebrew mirror source.

Second, the domestic

1. Tsinghua University source (installation, source change)

Mirrors.tuna.tsinghua.edu.cn/help/homebr… Mirrors.tuna.tsinghua.edu.cn/help/homebr…

1.1 Downloading the Installation scriptinstall.sh

$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git
$ cd install
Copy the code

1.2 the editorinstall.sh

BREW_REPO = "https://github.com/Homebrew/brew" # changed to:  BREW_REPO="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"Copy the code

1.3 runinstall.shInstall Homebrew

1.4 Replace existing upstream

# BREW program itself
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# homebrew-core
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# homebrew-cask
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

Test whether the work is normal after replacement
$ brew update
Copy the code

1.5 Replacing a Homebrew Bintray Image

  • Temporary replacement

    $ export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
    Copy the code
  • Permanent replacement

    # zsh
    $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
    $ source ~/.zshrc
    
    # bash
    $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
    $ source ~/.bash_profile
    Copy the code

2. USTC source(换源)

Mirrors.ustc.edu.cn/help/brew.g… Mirrors.ustc.edu.cn/help/homebr…

  • Replace existing upstream
# BREW program itself
$ cd "$(brew --repo)"
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# homebrew-core
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# homebrew-cask
$ cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
Copy the code
  • Replace Homebrew Bintray image
# zsh
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc

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

3. HomebrewCN(Installation, source change)

Gitee.com/cunkai/Home…

This is a domestic open source, installation + automatic source (university of Science and Technology), more convenient.

# zsh
$ /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

# bash
$ /bin/bash -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
Copy the code

4. Ali source

Developer.aliyun.com/mirror/home…

  • Replace existing upstream
# BREW program itself
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# homebrew-core
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# No Homebrew-Cask for the time being
Copy the code
  • Replace Homebrew Bintray image
# zsh
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc

# bash
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
Copy the code

Ali source is not currently recommended for Homebrew, which is why I put it in the last section. At present, there are problems such as instability, no HomeBREW-Cask or even failure. (as of 2020-12-09)

5. Reset the IP address to the official address

# BREW program itself
$ git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
# homebrew-core
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
# homebrew-cask
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git

Test whether the work is normal after replacement
brew update
Copy the code