背景简介
macOS 虽然基于 Unix,但它并没有一个像 Linux(apt、yum)那样方便的官方包管理器。如果你想安装一个 wget、git、nginx 或者 redis,你通常需要去官网下载 .dmg 文件、手动编译源码,非常麻烦。
Homebrew 解决了这个问题。它被称为 “The missing package manager for macOS”(macOS 上缺失的包管理器)。
前置信息
- Mac
详细信息
第一步: 从官网获取最新的安装脚本
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
******
==> /usr/bin/sudo /usr/sbin/chown root:wheel /etc/paths.d/homebrew
==> /usr/bin/sudo /bin/chmod a+r /etc/paths.d/homebrew
==> Updating Homebrew...
==> Installation successful!
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
==> Next steps:
- Run these commands in your terminal to add Homebrew to your PATH:
echo >> /Users/user/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/user/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
https://docs.brew.sh
- 根据提示信息进行配置
echo >> /Users/user/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/user/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
第二步: 查看安装结果
brew help
Example usage:
brew search TEXT|/REGEX/
brew info [FORMULA|CASK...]
brew install FORMULA|CASK...
brew update
brew upgrade [FORMULA|CASK...]
brew uninstall FORMULA|CASK...
brew list [FORMULA|CASK...]
Troubleshooting:
brew config
brew doctor
brew install --verbose --debug FORMULA|CASK
Contributing:
brew create URL [--no-fetch]
brew edit [FORMULA|CASK...]
Further help:
brew commands
brew help [COMMAND]
man brew
https://docs.brew.sh
可选: 加速
- 切换 Homebrew 核心库
# 替换 brew.git
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
- 配置 Bottles 镜像(二进制预编译包)
对于 macOS Catalina 及更高版本(使用 zsh shell):
source ~/.zshrc
对于 macOS Mojave 及更低版本(使用 bash shell):
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
- 重置配置
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
- zsh 用户: 编辑
~/.zshrc
文件,删除export HOMEBREW_BOTTLE_DOMAIN=...
这一行,然后运行source ~/.zshrc
。 - bash 用户: 编辑
~/.bash_profile
文件,删除export HOMEBREW_BOTTLE_DOMAIN=...
这一行,然后运行source ~/.bash_profile
。
以上便是本文的全部内容,感谢您的阅读,如遇到任何问题,欢迎在评论区留言讨论。