This article is transcoded by SimpRead, original address mirrors.tuna.tsinghua.edu.cn
Homebrew Usage Help | Mirror Site Usage Help | Tsinghua University Open Source Software Mirror Site, dedicated to providing high-quality open source software mirrors and Linux mirror sources for domestic and on-campus users, helping users access open source software more conveniently.
Homebrew / Linuxbrew Mirror Usage Help
Note: This mirror hosts the source code and formula / cask indexes for Homebrew / Linuxbrew (i.e., the contents updated by brew update). This mirror site also provides corresponding binary precompiled package mirrors, please refer to Homebrew bottles Mirror Usage Help.
This site provides the following repo under the https://github.com/Homebrew organization: brew, homebrew-core, homebrew-cask, homebrew-cask-fonts, homebrew-cask-versions, homebrew-command-not-found, homebrew-services, install.
Note: Since brew 3.3.0 (October 25, 2021), the Linuxbrew core repository linuxbrew-core has been deprecated. Linuxbrew users should migrate to homebrew-core and reset the mirror according to this usage help. Please refer to the Linuxbrew Mirror Migration Instructions section of this help for details.
Note: Since brew 4.0.0 (February 16, 2023), HOMEBREW_INSTALL_FROM_API will be the default behavior and does not need to be set. Most users no longer need to clone the homebrew-core repository, so setting the HOMEBREW_CORE_GIT_REMOTE environment variable is unnecessary; however, if you need to run brew development commands or brew is installed in non-official default prefix locations, you still need to set HOMEBREW_CORE_GIT_REMOTE. If you prefer not to install via API, you can set HOMEBREW_NO_INSTALL_FROM_API=1.
Note: Since brew 4.0.22 (June 12, 2023), homebrew-cask-drivers has been deprecated and all casks have been merged into the homebrew-cask repository. Commands to clone homebrew-cask-drivers have been removed from this help. Users who have cloned it can run brew untap homebrew/cask-drivers to remove this repository.
Daily Usage
You can set the following environment variables to use the Homebrew mirrors provided by this site:
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
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_PIP_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"
First Time Installing Homebrew / Linuxbrew
First, make sure bash, git, and curl are installed on your system. macOS users also need to install the Command Line Tools (CLT) for Xcode.
- For macOS users, bash, git, and curl come pre-installed. Run
xcode-select --installin the terminal to install CLT for Xcode. - For Linux users, bash is pre-installed. You only need to install git and curl additionally.
Next, enter the following commands in the terminal to set the environment variables:
export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
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"
Note: Since brew 4.0, HOMEBREW_INSTALL_FROM_API is the default behavior and does not need to be set; most users no longer need to clone the homebrew/core repository, so setting HOMEBREW_CORE_GIT_REMOTE is unnecessary. However, if running brew development commands or brew is installed in non-official default prefix locations, setting HOMEBREW_CORE_GIT_REMOTE is still required; if you prefer not to install via API, set HOMEBREW_NO_INSTALL_FROM_API=1.
Finally, run the following commands in the terminal to install Homebrew / Linuxbrew:
# Download the installation script from this mirror and install Homebrew / Linuxbrew
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
# Or install Homebrew / Linuxbrew using the official installation script from GitHub
/bin/bash -c "$(curl -fsSL https://github.com/Homebrew/install/raw/master/install.sh)"
This allows you to use the mirror during the initial installation as well. For more information, please refer to the Homebrew Official Installation Documentation.
* After a successful installation, you need to add the brew program specific paths to your environment variables:
-
For Homebrew on macOS devices based on Apple Silicon CPUs (running
uname -min the terminal should outputarm64):test -r ~/.bash_profile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile test -r ~/.zprofile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofileUsers on macOS with Intel CPUs (running
uname -moutputsx86_64) can skip this step. -
For Linuxbrew on Linux systems:
test -d ~/.linuxbrew && eval "$(~/.linuxbrew/bin/brew shellenv)" test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" test -r ~/.bash_profile && echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.bash_profile test -r ~/.profile && echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.profile test -r ~/.zprofile && echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.zprofileReferenced from https://docs.brew.sh/Homebrew-on-Linux.
Replace Existing Repository Upstreams
Replace the brew program source itself, the same for Homebrew / Linuxbrew:
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
brew update
The following is for Homebrew on macOS systems:
# Manually set
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
# Note: Since brew 4.0, most Homebrew users do not need to set mirrors for homebrew/core and homebrew/cask, only HOMEBREW_API_DOMAIN is needed.
# If you need to use Homebrew development commands (such as `brew cat <formula>`), you still need to set homebrew/core and homebrew/cask mirrors.
# Please execute the following two lines as needed:
brew tap --custom-remot
```e --force-auto-update homebrew/core https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
brew tap --custom-remote --force-auto-update homebrew/cask https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
# Tap repositories other than homebrew/core and homebrew/cask still need to set mirrors
brew tap --custom-remote --force-auto-update homebrew/cask-fonts https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
brew tap --custom-remote --force-auto-update homebrew/cask-versions https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-versions.git
brew tap --custom-remote --force-auto-update homebrew/command-not-found https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-command-not-found.git
brew tap --custom-remote --force-auto-update homebrew/services https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-services.git
brew update
# Or use the following few lines of commands to set up automatically
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
for tap in core cask{,-fonts,-versions} command-not-found services; do
brew tap --custom-remote --force-auto-update "homebrew/${tap}" "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-${tap}.git"
done
brew update
The following is for Linuxbrew on Linux systems:
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
# Note: Since brew 4.0, most Homebrew users using the default prefix (i.e., "/home/linuxbrew/.linuxbrew") do not need to set the homebrew/core mirror, only need to set HOMEBREW_API_DOMAIN.
# If it is not the default prefix or you need to use Homebrew's development commands (such as `brew cat <formula>`), you still need to set the homebrew/core mirror.
# Please execute the following commands as needed:
brew tap --custom-remote --force-auto-update homebrew/core https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# Tap repositories other than homebrew/core still need to set mirrors
brew tap --custom-remote --force-auto-update homebrew/command-not-found https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-command-not-found.git
brew tap --custom-remote --force-auto-update homebrew/services https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-services.git
brew update
Note: If users set the environment variables HOMEBREW_BREW_GIT_REMOTE and HOMEBREW_CORE_GIT_REMOTE, then every time brew update is run, the remote of the brew program itself and the Core Tap (homebrew-core) will be automatically set. It is recommended that users add these two environment variable settings into the shell’s profile settings.
test -r ~/.bash_profile && echo 'export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"' >> ~/.bash_profile # bash
test -r ~/.bash_profile && echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> ~/.bash_profile # bash
test -r ~/.bash_profile && echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> ~/.bash_profile
test -r ~/.profile && echo 'export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"' >> ~/.profile
test -r ~/.profile && echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> ~/.profile
test -r ~/.profile && echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> ~/.profile
test -r ~/.zprofile && echo 'export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"' >> ~/.zprofile # zsh
test -r ~/.zprofile && echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> ~/.zprofile # zsh
test -r ~/.zprofile && echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> ~/.zprofile
Linuxbrew Mirror Migration Instructions
The Linuxbrew core repository (linuxbrew-core) was deprecated on October 25, 2021 (starting from brew version 3.3.0). Linuxbrew users should migrate to homebrew-core. Linuxbrew users please reset mirrors according to the new mirror instructions. Note that before migration, please run brew update to update brew to version 3.3.0 or above. If any problems occur during the migration, you can use the following command to reinstall homebrew-core:
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
rm -rf "$(brew --repo homebrew/core)"
brew tap --custom-remote --force-auto-update homebrew/core https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
Restore Repository Upstream
(Thanks to Snowonion Lee for the explanation)
- For Homebrew on macOS systems
# The brew program itself, same for Homebrew / Linuxbrew
unset HOMEBREW_BREW_GIT_REMOTE
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew
# The following is for Homebrew on macOS systems
unset HOMEBREW_API_DOMAIN
unset HOMEBREW_CORE_GIT_REMOTE
BREW_TAPS="$(BREW_TAPS="$(brew tap 2>/dev/null)"; echo -n "${BREW_TAPS//$'\n'/:}")"
for tap in core cask{,-fonts,-versions} command-not-found services; do
if [[ ":${BREW_TAPS}:" == *":homebrew/${tap}:"* ]]; then # Only restore installed Taps
brew tap --custom-remote "homebrew/${tap}" "https://github.com/Homebrew/homebrew-${tap}"
fi
done
# Pull from remote again
brew update
- For Linuxbrew on Linux systems
# The brew program itself, same for Homebrew / Linuxbrew
unset HOMEBREW_BREW_GIT_REMOTE
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew
# The following is for Linuxbrew on Linux systems
unset HOMEBREW_API_DOMAIN
unset HOMEBREW_CORE_GIT_REMOTE
brew tap --custom-remote homebrew/core https://github.com/Homebrew/homebrew-core
brew tap --custom-remote homebrew/command-not-found https://github.com/Homebrew/homebrew-command-not-found
brew tap --custom-remote homebrew/services https://github.com/Homebrew/homebrew-services
# Pull from remote again
brew update
Note: After resetting to the default remote, users should delete the environment variables HOMEBREW_BREW_GIT_REMOTE and HOMEBREW_CORE_GIT_REMOTE from their shell’s profile settings to prevent the remote from being changed again when running brew update.