关于Homebrew的安装
Homebrew 是一款包管理工具,目前支持macOS和linux系统.
但是由于种种原因,安全的过程能让你奔溃。各种错误和卡顿。
相信这是每个程序员经历的过的痛苦。
homebrew主要有四个部分组成:brew、homebrew-core、homebrew-cask、homebrew-bottles。
| 名称 | 说明 |
|---|---|
| brew | homebrew源代码仓库 |
| homebrew-core | homebrew核心源 |
| homebrew-cask | 提供macOS应用和大型二进制文件 |
| homebrew-bottles | 预编译的二进制软件包 |
1、安装脚本说明
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install"
curl: (7) Failed to connect to http://raw.githubusercontent.com port 443: Operation timed out
2、安装过程说明
下面就是重点部分,排除你在安装过程中的各种问题。
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
如果出现上面问题,一直比较慢,请Control + C中断脚本执行如下命令:
并且切换到 homebrew 或者 手动创建homebrew 目录
cd "$(brew --repo)/Library/Taps/"
mkdir homebrew && cd homebrew
git clone git://mirrors.ustc.edu.cn/homebrew-core.git
如果其他部分也出现上述类似问题,也同样按如此做法搞定。
cask 同样也有安装失败或者卡住的问题,解决方法也是一样:
cd "$(brew --repo)/Library/Taps/"
cd homebrew
git clone git://mirrors.ustc.edu.cn/homebrew-cask.git
成功执行之后继续执行前文的安装命令:
/usr/bin/ruby -e "$(cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"
最后看到==> Installation successful!就说明安装成功了。
3、设置镜像
brew、homebrew/core是必备项目,
homebrew/cask、homebrew/bottles按需设置。
通过 brew config 命令查看配置信息。
git -C "$(brew --repo)" remote set-url origin git://mirrors.ustc.edu.cn/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin git://mirrors.ustc.edu.cn/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin git://mirrors.ustc.edu.cn/homebrew-cask.git
4、长期替换homebrew-bottles
zsh 替换 brew bintray 镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles >> ~/.zshrc
source ~/.zshrc
bash 替换brew bintray镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles >> ~/.bash_profile
source ~/.bash_profile
最后brew update
5、如何卸载Homebrew
使用官方脚本同样会遇到uninstall地址无法访问问题,可以替换为下面脚本:
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall"
6、Can't update or upgrade Homebrew
Error: homebrew-core is a shallow clone. To `brew update` first run:
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
则需要
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow