
Homebrew:The missing package manager for macOS。
Homebrew 是苹果系统的扩展包安装工具,可以以非常优雅的方式安装 MariaDB,Redis、等工具。下面就是安装Homebrew的教程,本教程使用国内的清华镜像作为Homebrew镜像源,这样可以改善软件下载速度,提升使用体验。
安装Command Line Tools (CLT) for Xcode的目的是为MacOS添加命令工具:git 和 curl
打开Mac的终端

在终端中输入命令,安装Command Line Tools (CLT) for Xcode
xcode-select --install
在终端输入以下几行命令设置环境变量,设定使用清华Homebrew镜像源:
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"然后,在终端运行以下命令以安装 Homebrew:
xxxxxxxxxxgit clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install/bin/bash brew-install/install.shrm -rf brew-install如果您设备是Apple Silicon CPU 设备上的 macOS 系统,则需要设置进行如下设置,如果是Intel CPU 系统则跳过这步。
在终端输入命令检查处理器类型:
uname -m如果得到:
arm64
则说明您使用的是 Apple Silicon CPU 设备上的 macOS 系统(ARM 处理器)需要进行如下设置:
x
test -r ~/.bash_profile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profiletest -r ~/.zprofile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofiletest -r ~/.zshrc && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc对基于 Intel CPU 设备上的 macOS 系统(命令行运行
uname -m应输出x86_64)的用户可跳过本步。
Homebrew默认仓库在境外,访问非常慢,替换为国内镜像仓库可以大大加快访问速度,这里设置是是清华镜像仓库,可以替换 brew 程序本身的源:
xxxxxxxxxxexport HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"for tap in core cask{,-fonts,-drivers,-versions} command-not-found; do brew tap --custom-remote --force-auto-update "homebrew/${tap}" "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-${tap}.git"donebrew update然后设置系统环境变量,如果用户设置了环境变量 HOMEBREW_BREW_GIT_REMOTE 和 HOMEBREW_CORE_GIT_REMOTE,则每次执行 brew update 时,brew 程序本身和 Core Tap (homebrew-core) 的远程将被自动设置。推荐用户将这两个环境变量设置加入 shell 的 profile 设置中:
xxxxxxxxxxtest -r ~/.bash_profile && echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> ~/.bash_profile # bashtest -r ~/.bash_profile && echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> ~/.bash_profiletest -r ~/.bash_profile && echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"' >> ~/.bash_profiletest -r ~/.profile && echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> ~/.profiletest -r ~/.profile && echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> ~/.profiletest -r ~/.profile && echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"' >> ~/.profiletest -r ~/.zprofile && echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> ~/.zprofiletest -r ~/.zprofile && echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> ~/.zprofiletest -r ~/.zprofile && echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"' >> ~/.zprofiletest -r ~/.zshrc && echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> ~/.zshrctest -r ~/.zshrc && echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> ~/.zshrctest -r ~/.zshrc && echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"' >> ~/.zshrc如果您熟悉 vim 等编辑名,您可以手动编辑 .zprofile .profile 和 .bash_profile文件。
如果您使用的是 zsh 编辑.zprofile即可