Homebrew is a package management tool for MacOS, similar to Ubuntu’s apt and Arch Linux’s pacman, with many useful functions such as install, uninstall, update, view, search, etc. Many useful functions. It is very convenient and quick to implement package management with a simple command, without you caring about various dependencies and file paths.

Homebrew

Installation and use of Homebrew

Homebrew installation

Homebrew is installed by simply typing a command in the command line. The specific command is available at official website.

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

Homebrew Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Install software
brew install [Software Name]

# Uninstall software
brew uninstall [Software Name]

# Search Software
brew search [Software Name]

# View the list of installed software
brew list

# Remove software
brew cleanup [Software Name]

# Check the software that needs to be updated
brew outdated

# Update software
brew upgrade [Software Name]

# Update Homebrew
brew update

# View Homebrew configuration information.
brew config

Homebrew configuration

Homebrew consists of four main parts: brew, homebrew-core, homebrew-cask, homebrew-bottles, which correspond to the following functions.

  • homebrew: source code repository
  • homebrew-core: Homebrew core source
  • homebrew-cask: provides installation of macos applications and large binaries
  • homebrew-bottles: pre-compiled binary packages

Homebrew’s default software source is not in China, so if you are a Chinese user, the download speed is very slow when installing.

You can modify the software source like other package management tools.

View current source

1
2
3
4
# View brew.git current source
cd "$(brew --repo)" && git remote -v
# View current source for homebrew-core.git
cd "$(brew --repo homebrew/core)" && git remote -v

Switching software sources

Mac OS started in 10.15 system, the default shell are changed to zsh, so here only introduce the method of terminal as zsh. Take CSTD source as an example.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Replace brew.git:
cd "$(brew --repo)" && git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

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

# Replace homebrew-cask.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" && git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

# Replace homebrew-bottles mirror
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.zprofile

# Effective immediately
source ~/.zshrc

Other sources.

Restore the default source

1
2
3
4
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
brew update

The homebrew-bottles configuration can only be deleted manually by removing the HOMEBREW_BOTTLE_DOMAIN=https://mirrors.xxx.com content from the ~/.zprofile file and executing source ~/.zprofile.

other content

Currently cask is reading software sources from GitHub, and GitHub Api has restrictions on access, so if you use it more frequently, you can request an Api Token and then configure it to HOMEBREW_GITHUB_API_TOKEN in the environment variable.

Append to the .zprofile, taking care to replace yourtoken:

1
2
echo 'export HOMEBREW_GITHUB_API_TOKEN=yourtoken' >> ~/.zprofile
source ~/.zprofile