安装 Homebrew#

打开终端#

Command⌘-空格 打开聚焦搜索, 搜索 终端 并打开.

备注

注意此时的窗口样式, 当输入命令后再次出现类似样式时, 说明命令执行完毕:

../../_images/MacOS%E7%BB%88%E7%AB%AF_%E7%AA%97%E5%8F%A3%E6%A0%B7%E5%BC%8F.png

终端窗口样式#

安装 XCode#

输入 xcode-select --install回车, 在弹出的页面中点击 安装, 再点击 同意, 等待安装完成.

../../_images/MacOS_%E5%AE%89%E8%A3%85xcode-select.png

安装 xcode-select#

设置 Homebrew/Linuxbrew 安装镜像#

在终端输入以下命令设置安装镜像:

提示

对于以下执行的命令块, 你应该依次执行, 对每个命令进行如下操作:

复制命令

通过 鼠标移到代码右上角 ‣ 点击出现的按钮 来复制命令.

粘贴命令到终端中

在窗口内 右键 然后选择 粘贴 (Paste).

请勿使用 Control-V 进行粘贴! 如果习惯性按了, 请狂按几次 删除键.

执行命令

通过在窗口内 回车 执行命令, 当终端再次出现 终端刚打开时的窗口样式 时, 命令执行完毕.

如果命令停住不继续执行, 可能是因为这个命令需要你进行再次确认; 对于本教程而言, 狂敲几次 回车 即可.

如果实在卡住太长时间, 你可以 Ctrl-C 终止执行, 然后重新输入并执行命令.

确认完成命令

当终端再次出现 终端刚打开时的窗口样式 时, 命令执行完毕. 这时, 你可以执行下一条命令.

export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"

安装 Homebrew/Linuxbrew#

在终端运行以下命令以安装 Homebrew/Linuxbrew.

/bin/bash -c "$(curl -fsSL https://mirrors.ustc.edu.cn/misc/brew-install.sh)"

备注

键入这一行命令后, 需要 输入电脑密码回车、再 回车 以继续!

../../_images/MacOS_%E8%BE%93%E5%85%A5%E7%94%B5%E8%84%91%E5%AF%86%E7%A0%81.png

输入电脑密码#

设置 Homebrew/Linuxbrew 环境变量#

输入 uname -m回车, 如果输出 arm64 则需要添加环境变量, 否则跳过这一部分.

将 brew 程序的相关路径加入到环境变量中.

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bashrc
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.profile
eval "$(/opt/homebrew/bin/brew shellenv)"

备注

更泛用的方式是 Homebrew/Linuxbrew 安装完成后, 查看 终端 提示的 Next steps 并逐步进行.

../../_images/MacOS_Next_steps.png

Next Steps#

配置下载镜像源#

备注

如果按照 设置 Homebrew/Linuxbrew 环境变量 备注中的 Next steps 操作了, 跳过这一步.

echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"' >> ~/.bashrc
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"' >> ~/.bashrc
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"' >> ~/.bashrc
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"' >> ~/.bashrc
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"' >> ~/.bash_profile
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"' >> ~/.bash_profile
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"' >> ~/.bash_profile
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"' >> ~/.bash_profile
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"' >> ~/.zshrc
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"' >> ~/.zshrc
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"' >> ~/.zshrc
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"' >> ~/.zshrc
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"' >> ~/.zprofile
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"' >> ~/.zprofile
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"' >> ~/.zprofile
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"' >> ~/.zprofile
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"' >> ~/.profile
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"' >> ~/.profile
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"' >> ~/.profile
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"' >> ~/.profile

设置 Homebrew 自动更新软件#

警告

此部分在安装时需要确保网络可访问 github, 不行请跳过.

brew tap homebrew/autoupdate

安装好后, 使用 brew autoupdate --help 可查看命令说明, 以下是我使用的:

brew install pinentry-mac
mkdir -p /Users/feignclaims/Library/LaunchAgents
brew autoupdate start --upgrade --greedy --cleanup --sudo