Homebrew是Mac上非常优秀的软件包管理工具。
安装
- 打开终端,输入以下命令:
1
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
其他安装方法
- 由于国内的网络环境等问题,使用官方的安装方法可能无法安装成功。可以尝试使用其他更适合国内网络环境的安装方法,参考地址:https://brew.idayer.com/。
- 安装homebrew-core
1
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
- 安装homebrew-cask
1
2
3cd "$(brew --repo)/Library/Taps/homebrew/"
git clone https://mirrors.ustc.edu.cn/homebrew-cask.git
修改源
为了加速以后使用Homebrew安装其他软件的过程,建议设置软件源为国内源。
- 查看源
1
2
3cd "$(brew --repo)" && git remote -v
cd "$(brew --repo homebrew/core)" && git remote -v
cd "$(brew --repo homebrew/cask)" && git remote -v - 设置源(中科大的源)
1
2
3
4
5
6
7git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
brew update - 设置bottles镜像
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# 从macOS Catalina(10.15.x) 版开始,Mac使用zsh作为默认shell,使用的配置文件:.zprofile
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zprofile
source ~/.zprofile
# 如果是以前的macOS版本,Mac使用bash作为默认shell,使用的配置文件:.bash_profile
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
```
重置为官方源
- 可以通过以下命令还原回官方源
``` shell
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
zsh 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置
vi ~/.zprofile
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
source ~/.zprofile
bash 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置
vi ~/.bash_profile
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
source ~/.bash_profile
brew update
卸载
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"