MacOS M1安装Homebrew

1. 运行安装指令

打开Terminal(shell为zsh,配置文件为~/.zshrc,后边修改PATH时就是修改这个文件),运行:

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

运行结果:

1
2
3
~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
==> Checking for `sudo` access (which may request your password)...
Password:

这里要输入密码(因为只有管理员身份才能安装)。

接下来会显示:

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
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew
==> The following new directories will be created:
/opt/homebrew/bin
/opt/homebrew/etc
/opt/homebrew/include
/opt/homebrew/lib
/opt/homebrew/sbin
/opt/homebrew/share
/opt/homebrew/var
/opt/homebrew/opt
/opt/homebrew/share/zsh
/opt/homebrew/share/zsh/site-functions
/opt/homebrew/var/homebrew
/opt/homebrew/var/homebrew/linked
/opt/homebrew/Cellar
/opt/homebrew/Caskroom
/opt/homebrew/Frameworks

Press RETURN/ENTER to continue or any other key to abort:

这里敲回车继续安装。

然后就开始安装所有需要的工具,这个过程可能会比较慢:

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
34
35
36
37
38
39
...
==> Downloading and installing Homebrew...
remote: Enumerating objects: 212202, done.
remote: Counting objects: 100% (44/44), done.
remote: Compressing objects: 100% (44/44), done.
remote: Total 212202 (delta 0), reused 44 (delta 0), pack-reused 212158
Receiving objects: 100% (212202/212202), 59.21 MiB | 824.00 KiB/s, done.
Resolving deltas: 100% (156120/156120), done.
From https://github.com/Homebrew/brew
...
==> Tapping homebrew/core
remote: Enumerating objects: 1232883, done.
remote: Counting objects: 100% (601/601), done.
remote: Compressing objects: 100% (253/253), done.
Resolving deltas: 100% (851035/851035), done.
From https://github.com/Homebrew/homebrew-core
* [new branch] master -> origin/master
HEAD is now at 566fbd2f195 x265: use `on_{system}` blocks
Updated 1 tap (homebrew/core).
Warning: /opt/homebrew/bin is not in your PATH.
Instructions on how to configure your shell for Homebrew
can be found in the 'Next steps' section below.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/[username]/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
https://docs.brew.sh

可以看到“Installation successful!”的提示。

如果出现了一些errors,重新再安装一遍。

2. 将homebrew添加到PATH

“Installation successful!”的提示上面还有一行Warning:

1
Warning: /opt/homebrew/bin is not in your PATH.

提示你homebrew的可执行文件没有被添加到PATH中。

在home下创建.zshrc文件,然后添加下面内容(如果已经有这个文件,直接在文件末尾添加):

1
export PATH=/opt/homebrew/bin:$PATH

3. 使上面的PATH内容立即生效

执行:

1
source ~/.zshrc

4. 检查是否安装成功

1
brew help

执行结果:
执行brew help

说明安装成功。

参考链接

[1] How to install homebrew on M1 mac:https://stackoverflow.com/questions/66666134/how-to-install-homebrew-on-m1-mac