Introduction

Function: Homebrew is the easiest and most flexible way to install the UNIX tools Apple didn’t include with macOS.

Depend on: 依赖于git来完成包的安装

Install

Install Self

Reference: [Install Homebrew(https://brew.sh/)

Configure

默认安装目录: 所有通过brew安装的包的目录, /usr/local/Cellar/程序名/版本号/, 自动创建bin目录的软链接.

Command

Reference: brew command

Format

1
2
brew command [--verbose|-v] [options] [formula]
brew --version

Command

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
27
28
29
30
31
32
33
# Install
brew install package
# uninstall
brew uninstall formula
# Update
brew update formula
# Upgrade
brew upgrade formula or brew upgrade

# 包列表(list all installed formulae['fɔːmjʊlə]-公式,准则)
brew list
# 搜索包(Search at local taps and github taps)
brew search formula
# 显示软件信息, 显示所有已安装版本的包信息
brew info formula
# 包依赖
brew deps formula

# 删除/usr/local/下的无效链接
brew prune
# 清除已安装软件的所有历史版本
brew cleanup formula or brew cleanup
# 列出所有可升级的包
brew outdated

# 删除unexpected的文件, 添加 PATH等
# Check
brew doctor

# 链接最近使用的版本
brew link formula
# 链接到指定版本
brew switch formula Versions

Configure

国内源

Reference: brew 国内源

Configure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 中科大
# 替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https:://mirrors.ustc.edu.cn/brew.git
# 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

# 清华备份
cd "$(brew --repo)
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core”
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
brew update

# 切换回官方
# 重置brew.git:
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

# 重置homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git

Multiple Version Application

Reference: Multiple Mysql Versions with Homebrew

根据如下步骤: unlink–>list all version–>switch
Clean: brew cleanup mysql