
Homebrew —— Mac 端超级好用的包管理神器
Homebrew —— macOS 上最流行的包管理工具,让安装、更新、管理软件变得像 brew install 一样简单!
✨ 文章概要
🎯 什么是 Homebrew
- macOS(及 Linux)上的开源包管理器,由 Max Howell 开发
- 一行命令安装软件,自动处理依赖关系
- 核心组件:brew(包管理)+ cask(GUI 应用管理)+ tap(第三方仓库)
🔧 安装 Homebrew
# 官方源安装
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# 国内源安装(中科院,推荐中国大陆用户使用)
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
# 卸载 Homebrew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"
🔄 换源加速
使用国内镜像源可大幅提升下载速度,推荐以下源:
中科大(推荐)
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
brew update
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile
source ~/.bash_profile
阿里云
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
brew update
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
清华
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
brew update
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile
source ~/.bash_profile
📦 常用命令
| 命令 | 说明 |
|---|---|
brew search <关键词> |
搜索软件包 |
brew install <包名> |
安装命令行工具 |
brew install --cask <应用名> |
安装 GUI 应用 |
brew info <包名> |
查看包详细信息 |
brew list |
列出已安装包 |
brew outdated |
查看可更新的包 |
brew upgrade <包名> |
升级指定包 |
brew update |
更新 Homebrew 自身 |
brew uninstall <包名> |
卸载包 |
brew cleanup |
清理旧版本和缓存 |
brew pin <包名> |
锁定包版本,防止意外升级 |
brew unpin <包名> |
取消锁定 |
🛠 服务管理
brew services list # 查看已安装的服务列表
brew services run <服务名> # 启动服务(仅启动不注册)
brew services start <服务名> # 启动服务并注册开机自启
brew services stop <服务名> # 停止服务并取消注册
brew services restart <服务名> # 重启服务
🧰 辅助工具
- Cakebrew —— Homebrew 的 GUI 管理工具,可视化操作包管理

- LaunchRocket —— 图形化管理 Homebrew 安装的后台服务

🌐 参考资源
- Homebrew 官网:https://brew.sh/
- 可用包搜索:https://formulae.brew.sh/
- GitHub 仓库:https://github.com/Homebrew/brew