Brew
Index
Install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Repository Replacement
【Source Repository Types】
brew
: Homebrew source code repositoryhomebrew-core
: Homebrew core sourcehomebrew-cask
: Repository for MacOS applications and large binary installationshomebrew-bottles
: Precompiled binary software packages
Brew Resource
中科大
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
阿里巴巴
git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
清华大学
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
Core Resource
中科大
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
阿里巴巴
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
清华大学
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
Cask Resource
中科大
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
阿里巴巴
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-cask.git
清华大学
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
Bottles Resource
If your shell is
zsh
, write tozshrc
; if it is bash, write tobash_profile
.
中科大
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.zshrc
阿里巴巴
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
echo 'export HOMEBREW_API_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles/api' >> ~/.zshrc
清华大学
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles' >> ~/.zshrc
Finally, refresh the configuration.
source ~/.zshrc
Restore the source.
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
sed '/export HOMEBREW_BOTTLE_DOMAIN/'d ~/.zshrc
source ~/.zshrc
brew update
Commonly Used Commands.
# 搜索包
brew search node
# 安装最新版
brew install node
# 安装指定版本
brew install node@14.16.8
# 查看已安装的包列表
brew list
# 查看某个包的详细信息
brew info node
# 清除安装缓存
brew cleanup
# 更新brew
brew update
# 更新软件包
brew upgrade node
# 卸载软件包
brew uninstall node
# 查看brew配置
brew config
# 诊断brew
brew doctor
# 开启、关闭、重启服务
brew service start|stop|restart nginx
# 服务列表
brew services list
Install an older version of PHP.
【Tip】
The newer versions of the Homebrew repository only offer PHP versions starting from 7.4
, which poses a challenge for projects requiring older versions of PHP.
Add the repository for older versions of PHP.
brew tap shivammathur/php
At this point, you should be able to locate various versions of PHP for selection.
Switching between multiple versions
# 安装php版本切换器
brew install brew-php-switcher
# 切换版本
brew-php-switcher 8.1