Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷。Homebrew是Mac OS 不可或缺的套件管理器。
由于官方镜像访问受限,以下安装使用清华大学的镜像。
1、安装 CLT for Xcode
xcode-select --install
2、在终端输入以下几行命令设置环境变量:
if [[ "$(uname -s)" == "Linux" ]]; then BREW_TYPE="linuxbrew"; else BREW_TYPE="homebrew"; fi
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/${BREW_TYPE}-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/${BREW_TYPE}-bottles"
3、运行以下命令以安装 Homebrew
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
4、以下针对基于 Apple Silicon CPU 设备上的 macOS 系统(命令行运行 uname -m
应输出 arm64
)上的 Homebrew:
test -r ~/.bash_profile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
test -r ~/.zprofile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
5、替换现有仓库上游
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
git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
git -C "$(brew --repo homebrew/cask-versions)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-versions.git
6、重新设置 git 仓库 HEAD
brew update-reset
7、更新Homebrew
brew update
8、其他基本操作命令
#查看帮助
brew help
brew -h
#安装任意包
brew install <packageName>
#卸载任意包
brew uninstall <packageName>
#查询可用包
brew search <packageName>
#查询已安装包列表
brew list
#查看任意包信息
brew info <packageName>
#查看版本
brew -v
#更新指定包
brew upgrade <packageName>
#列出软件包的相关依赖
brew deps <packageName>
#列出可以更新的软件包
brew outdated
#整理重复语句
open ~/.zshrc -e、open ~/.bash_profile -e
9、文件位置
与intel芯片不同,M1安装的homebrew在 /opt/homebrew 目录下:
文件: /opt/homebrew/cellar/appname
配置文件: /opt/homebrew/etc/appname
日志文件: /opt/homebrew/var/log