什么是 Homebrew
homebrew.png
Homebrew 是 macOS 的软件包的管理器。使用 Homebrew 可以安装 Mac 没有预装但 你需要的东西。它会将软件包安装到独立目录 。
Homebrew 的安装
[Homebrew 对于 macOS 用户需额外要求安装 Command Line Tools (CLT) for Xcode,有两种安装方式如下:
-
官方脚本一键安装,安装目录在
/usr/local
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
自定义安装路径
-
安装仓库
# 克隆仓库(镜像源替换 https://github.com/Homebrew/brew) git clone https://github.com/Homebrew/brew homebrew # 配置环境变量 eval "$(homebrew/bin/brew shellenv)" # 更新 brew update --force --quiet # 改读写权限 chmod -R go-w "$(brew --prefix)/share/zsh"
-
在
~/.zshrc
配置环境变量export PATH=homebrew的路径/bin:$PATH
-
镜像源的问题
清华大学开源软件镜像站/Homebrew / Linuxbrew 镜像使用帮助
首次安装 Homebrew
-
配置环境变量
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_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
执行上面 Homebrew 的安装即可
替换现有源
cd "$(brew --repo)" && git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
Command-Line API
[以下是部分常使用的命令,其它的可以参考 man brew
、 brew commands
或者 brew 文档
- brew list 列出已安装的软件
- brew outdated 列出那些软件需要更新
- brew update 更新brew
- brew upgrade xxx 升级指定软件
- brew home 用浏览器打开brew的官方网站
- brew deps 显示包依赖
- brew cleanup 删除所有软件升级后的遗留旧版本