1. 官方安装
终端输入命令:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
要么是连接失败,要么是网速超慢导致失败。
2. 镜像安装
-
从上面命令的链接中下载脚本 🔗 install.sh
-
打开脚本文件,修改远程仓库地址:
# 找到如下代码 BREW_REPO="https://github.com/Homebrew/brew" # 注释掉替换为中科大镜像 BREW_REPO="https://mirrors.ustc.edu.cn/brew.git" # 或清华大学镜像 BREW_REPO="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
-
终端执行该脚本(可通过拖入终端窗口的方式)
-
中途会卡住:
==> Tapping homebrew/core Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
因为 homebrew-core 的 git 源没有替换。
此时中断命令的执行。(或许是 Command + C ?) -
从中科院的镜像地址克隆 homebrew-core:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git clone git://mirrors.ustc.edu.cn/homebrew-core.git
-
更新 homebrew:
brew update
-
检查一下:
brew doctor
-
安装完成验证:
# 查看版本 brew -v # 查看配置信息 brew config
3. 设置镜像
brew
、homebrew-core
是必需项目,homebrew-cask
、homebrew-bottles
按需设置。
cask 软件仓库:提供 macOS 应用和大型二进制文件。
bottles 源:Homebrew 预编译二进制软件包。
brew
# 进入本地仓库目录
cd "$(brew --repo)"
# 查看远程仓库(可选操作)
git remote -v
# 设置远程仓库为中科大镜像
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 更新
brew update
清华镜像:https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
🔗 Homebrew/Linuxbrew 镜像使用帮助
homebrew-core
# 进入本地仓库目录
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
# 查看远程仓库(可选操作)
git remote -v
# 设置远程仓库为中科大镜像
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 更新
brew update
清华镜像:https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
homebrew-cask
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
homebrew-bottles
临时设置:
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
长期替换:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
恢复
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git
cd "$(brew --repo)/Library/Taps/caskroom/homebrew-cask"
git remote set-url origin https://github.com/Homebrew/homebrew-cask.git
brew update
参考文档:
🔗 mac下镜像飞速安装Homebrew教程
🔗 Mac HomeBrew国内镜像安装方法