🍺 Homebrew 官网:https://brew.sh/
虽然本文属于Linux基础系列,但由于博主使用的是macOS(M1)系统,所以讲解也会围绕该系统展开。
Homebrew 是 macOS 上的强大的包管理工具,可以高效管理各种软件包。Homebrew 由 Max Howell 从 2009 年开始开发并在 GitHub 上开源,最初在 macOS 用户中和 Ruby 社区中得到广泛使用,2019 年 Homebrew 的子项目 Linuxbrew 被合并进了 Homebrew,使得它能够在 Linux 和 WSL 上运行。
使用官方的命令安装:
/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)"
安装目录为 /opt/homebrew。
在命令行执行(请先确保shell为zsh)
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile && source ~/.zprofile
以清华源为例,依次执行下面五个命令
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' >> ~/.zprofile && source ~/.zprofile

| 命令 | 描述 |
|---|---|
brew install [--cask] | 安装指定软件(其中 --cask 可选,若加上则代表安装带有GUI的软件) |
brew uninstall [--cask] | 卸载指定软件 |
brew reinstall [--cask] | 重新安装指定软件 |
brew list | 列出所有已安装软件 |
brew info | 显示指定软件信息 |
brew search | 搜索软件 |
| 命令 | 描述 |
|---|---|
brew -v | 查看brew版本 |
brew update | 升级Homebrew本身 |
brew outdated | 检测已过时的软件 |
brew upgrade | 升级所有已过时的软件 |
brew upgrade | 升级指定的软件 |
brew pin | 禁止指定软件升级 |
brew unpin | 解锁禁止升级 |
| 命令 | 描述 |
|---|---|
brew cleanup -n | 列出需要清理的内容 |
brew cleanup | 清理指定的软件 |
brew cleanup | 清理所有过时的软件 |
[1] Homebrew快速安装
[2] Homebrew国内如何自动安装(国内地址)(Mac & Linux)
[3] Homebrew常规使用教程