homebrew是一款非常优秀的mac端的包管理软件,几乎是开发者必备,安装方法:
# 从阿里云下载安装脚本并安装 Homebrew
git clone https://mirrors.aliyun.com/homebrew/install.git brew-install
/bin/bash brew-install/install.sh
rm -rf brew-install
# 也可从 GitHub 获取官方安装脚本安装 Homebrew
/bin/bash -c "$(curl -fsSL https://github.com/Homebrew/install/raw/master/install.sh)"
Homebrew
主要有四个部分组成: brew
、homebrew-core
、homebrew-bottles
、homebrew-cask
名称 | 说明 |
brew | Homebrew 源代码仓库 |
homebrew-core | Homebrew 核心软件仓库 |
homebrew-bottles | Homebrew 预编译二进制软件包 |
homebrew-cask | 提供 macOS 应用和大型二进制文件 |
由于homebrew的默认下载源在国外,非常不稳定,需要改为国内源。
第一步先查看brew现有的下载源,确认是否在默认下载源。
git -C "$(brew --repo)" remote get-url origin
git -C "$(brew --repo homebrew/core)" remote get-url origin
git -C "$(brew --repo homebrew/cask)" remote get-url origin
接着更改为阿里源:
# 替换brew.git:
git -C "$(brew --repo)" remote set-url origin 'https://mirrors.aliyun.com/homebrew/brew.git'
# 替换homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin 'https://mirrors.aliyun.com/homebrew/homebrew-core.git/'
# 替换homebrew-cask.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin 'https://mirrors.aliyun.com/homebrew/homebrew-cask.git'
# 刷新源,可能会需要一些时间
brew update
把brew二进制软件包地址写进zsh配置文件:
# 更新zsh终端配置文件
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
# 刷新配置文件
source ~/.zshrc
Homebrew 4.0进行了一项最大的改动,组织方式从Git
仓库管理改为JSON
文件下载。以上方法就不适用了,请用以下方法更新下载源为国内。
JSON
配置文件会从formulae.brew.sh下载,本地的homebrew-core
、homebrew-cask
两个仓库都不会被使用。
目前访问JSON
文件,即https://formulae.brew.sh/api/formula.json这样的文件,速度实在是太慢了,初次安装,以及每次update
都可能会提示。所以将JSON的官网地址替换为阿里源地址,一并写入zsh配置文件。
# brew下载镜像替换为阿里源,并写入zsh配置文件
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
# brew4.x API加速
echo 'export HOMEBREW_API_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles/api' >> ~/.zshrc
# 刷新配置文件生效
source ~/.zshrc
新版JSON Api
的好处是之前本地的homebrew-core
、homebrew-cask
仓库都可以删除掉了,这样会节省不少硬盘空间,删除命令如下:
brew untap homebrew/core
brew untap homebrew/cask