- 一些常用核心概念
formula (e) | 安装包的描述文件,formulae 为复数 |
cellar | 安装好后所在的目录 |
keg | 具体某个包所在的目录,keg 是 cellar 的子目录 |
bottle | 预先编译好的包,不需要现场下载编译源码,速度会快很多;官方库中的包大多都是通过 bottle 方式安装 |
tap | 下载源,可以类比于 Linux 下的包管理器 repository |
cask | 安装 macOS native 应用的扩展,你也可以理解为有图形化界面的应用。 |
bundle | 描述 Homebrew 依赖的扩展 |
homebrew 安装脚本(清华源)
- 官方一键安装脚本
/bin/bash -c "$(curl -fsSL https://github.com/Homebrew/install/raw/master/install.sh)"
- macOS 用户需要安装 Command Line Tools (CLT) for Xcode
xcode-select --install
设置环境变量
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"- 部分用户无需再克隆 homebrew/core 仓库,故无需设置
HOMEBREW_CORE_GIT_REMOTE环境变量 - 但若需要运行
brew的开发命令或者brew安装在非官方支持的默认 prefix 位置,则仍需设置HOMEBREW_CORE_GIT_REMOTE环境变量
export HOMEBREW_INSTALL_FROM_API=1- 自
brew4.0 起,HOMEBREW_INSTALL_FROM_API会成为默认行为,无需设置
运行安装脚本
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
默认安装路径 cellar
/opt/homebrew- Apple Silicon
/usr/local- for macOS Intel
/home/linuxbrew/.linuxbrew- for Linux
切换国内镜像源
- 参考资料
- 假设使用 zsh 终端
替换 brew 程序本身的源
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
brew update
设置 Homebrew Bottles 环境变量
- 写入 profile 持久化
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"' >> ~/.zprofileecho 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"' >> ~/.zprofile
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"
针对 macOS 系统上的 Homebrew 更新 brew 源(core, cask, other)
vim switch-brew-source.sh
- core 和 cask 按需执行
chmod +x switch-brew-source.sh
bash switch-brew-source.sh
或者通过以下指令执行更新
HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
for tapin core cask command-not-found;do brew tap --custom-remote --force-auto-update "homebrew/${tap}" "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-${tap}.git" done
brew update
复原仓库上游
- 重置回默认远程后,用户应该删除 shell 的 profile 设置中的环境变量
HOMEBREW_BREW_GIT_REMOTE和HOMEBREW_CORE_GIT_REMOTE以免运行brew update时远程再次被更换
- 针对 macOS 系统上的 Homebrew
管理 Homebrew
brew update- 更新 Homebrew 本体
brew doctor- 检查 Homebrew 环境
brew tap [user/repo]- 添加源
homebrew-cask-fonts- 提供代码字体
- 安装 source code pro 字体
brew tap homebrew/cask-fontsbrew cask install font-source-code-pro
一些特殊源
Homebrew 常用指令
brew install <formula>
brew search <keyword>
brew list- 查看已安装的所有软件
brew list <formula>- 查看已安装软件文件路径
brew outdated- 查看有可用更新的软件
brew upgrade <formula>- 更新特定软件
brew uninstall <formula>
brew cleanup <formula>- 相当于 autoremove
Homebrew 管理后台软件
- 软件日志位置
/opt/homebrew/var/log
brew services [list]- 查看
brew services info <formula>
brew services start <formula>- 运行并添加到开机时启动
- 相当于
enable --now
brew services run <formula>- 仅运行
brew services restart <formula>
brew services stop <formula>- 停止运行并移除开机时启动
- 相当于
disable --now - 通过添加
--keep避免移除开机时启动
使用 Brewfile 完成环境迁移
brew bundle dump --global --force- 完成当前环境的导出到
~/.Brewfile文件 --describe可以添加每个包的描述
brew bundle install- 新电脑执行安装
- Author:白鸟3
- URL:https://blog.kun2peng.top/operation/brew_intro
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
