正题开始之前, 如果对 Homebrew 不太了解, 去搜一下先去了解一下
常见命令
brew –help # 帮助
brew install git # 安装git
brew uninstall git # 卸载git
brew search git # 在源中搜索期望的包
brew info + 包名 # 在源中搜索期望的包,并且打印更详细的信息
brew list # 列出所有安装的包
brew services list # 列出所有正在运行的包
brew services restart # 重启
brew services start # 启动
brew services stop # 停止
brew update # 所有更新
brew upgrade git # 更新git
brew outdated # 会列出所有有新版本的程序
brew cleanup git # 清理 git
brew cleanup # 清理过期的formula
brew outdated
brew doctor # 检查有没有问题
Homebrew 通过 Git 来工作的, 默认的源是 Github. 因为众所周知的原因, update超级慢!通过brew update -v可以查看update执行的详细信息, 找到究竟是哪一步比较慢(管他哪一步慢, 往下看
解决办法无外乎两种: 1. 切换成国内源 2. 走 Proxy
这里采用第一种方法, 步骤如下:
切换到 Homebrew 目录
cd "$(brew --repo)"
查看远程仓库 git remote -v. 默认的使用的github。
删除远程: git remote rm origin
添加阿里源 :git remote add origin https://mirrors.aliyun.com/homebrew/brew.git
切换成阿里源: it remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
替换 homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
查看远程仓库 git remote -v. 默认的使用的github。
删除远程: git remote rm origin
添加阿里源 :git remote add origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
切换成阿里源: git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
替换 homebrew-bottles: 二进制文件
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
替换 homebrew-cask.git: cask 表示 GUI 应用的源, 阿里云没有提供 cask 源, 故使用 USTC 源
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
git remote rm origin
git remite add origin https://mirrors.ustc.edu.cn/homebrew-cask.git
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
复原
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
brew update