介绍
Homebrew
是一款包管理工具,目前支持macOS和Linux系统。主要有四个部分组成: brew
、homebrew-core
、homebrew-cask
、homebrew-bottles
。
名称 | 说明 |
---|---|
brew | Homebrew源代码仓库 |
homebrew-core | Homebrew 核心源 |
homebrew-cask | 提供 macOS 应用和大型二进制文件的安装 |
homebrew-bottles | 预编译二进制软件包 |
建议使用镜像助手 - Homebrew安装。
1. 初次安装,并且需要换其他源
请使用镜像助手获取不同源/系统和shell的安装脚本。
macOS/zsh 中科大源脚本为:
# 1.执行安装脚本
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
# 2.安装完成后设置
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.zshrc
source ~/.zshrc
2. 已经安装过,需要换源
更换源的时候:
brew
、homebrew/core
是必备项目
homebrew/cask
、homebrew/bottles
按需设置
- macOS/zsh更换清华源
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 -v
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles' >> ~/.zshrc
source ~/.zshrc
- macOS/zsh更换中科大源
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
brew update -v
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.zshrc
source ~/.zshrc
- 恢复默认源
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
brew update -v
然后还需删除手动删除~/.zshrc
文件中的 HOMEBREW_BOTTLE_DOMAIN=https://mirrors.xxx.com
内容
3. 官网的安装方法
export HOMEBREW_BREW_GIT_REMOTE="..." # put your Git mirror of Homebrew/brew here
export HOMEBREW_CORE_GIT_REMOTE="..." # put your Git mirror of Homebrew/homebrew-core here
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
实际上,就可以通过HOMEBREW_BREW_GIT_REMOTE
和HOMEBREW_CORE_GIT_REMOTE
这两个环境变量,临时更改源brew和brew/core
两个源。如果这两个清空了,那就使用git remote的默认源。
4. 查看当前源
cd $(brew --repo)
git remote -v
cd $(brew --repo homebrew/core)
git remote -v
cd $(brew --repo homebrew/cask)
git remote -v
参考资料:
1.homebrew | 清华大学开源软件镜像站
2. Homebrew 源使用帮助 — USTC Mirror Help 文档
3. Installation — Homebrew Documentation