How to install Homebrew on macOS

First, ensure that bash, git, and curl are installed on your system. macOS comes with bash and git preinstalled; you only need to install the Command Line Tools for Xcode separately.

  • In Terminal, run xcode-select --install to install them.

Next, run the following commands in Terminal to set environment variables:

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_INSTALL_FROM_API=1

Finally, run the following command in Terminal to install Homebrew:

# Download and install the Homebrew / Linuxbrew installation script from the mirror
git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
/bin/bash brew-install/install.sh
rm -rf brew-install

# Alternatively, download and install the official Homebrew / Linuxbrew installation script from GitHub
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

After successful installation, add the brew executable’s path to your environment variables:

Users running macOS on Intel-based Macs (where uname -m outputs x86_64) may skip this step.

Users running macOS on Apple Silicon (M-series chips) (where uname -m outputs arm64) should run:

test -r ~/.bash_profile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
test -r ~/.zprofile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile