Homebrew是 mac的包管理器,仅需执行相应的命令,就能下载安装需要的软件包,可以省掉自己去下载、解压、拖拽(安装)等繁琐的步骤。 比如安装服务器 nginx,打开终端执行以下命令即可安装:brew install nginx
目前支持macOS和linux系统。主要有四个部分组成: brew、homebrew-core 、homebrew-cask、homebrew-bottles。
名称 | 说明 |
brew | Homebrew 源代码仓库 |
homebrew-core | Homebrew 核心源 |
homebrew-cask | 提供 macOS 应用和大型二进制文件的安装 |
homebrew-bottles | 预编译二进制软件包 |
1.安装
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
出现一个问题: 要么下载极其龟速,要么直接出现如下提示:
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
原因:这是 http://raw.githubusercontent.com 访问不稳定引起的。
换一种科学高效的安装方法,即方法二
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"
注:注意这里的速度,几百kib/s或几m/s才是正常的。若只有几kib/s,通常为无效的安装方法,一般加载了百分之几十后就会报错。
2.安装时出现的问题
1)若出现 Error: Checksum mismatch.
这里是由Homebrew目录下的portable-ruby-2.6.3_2.yosemite.bottle.tar.gz文件引起的安装中断,只需要到上面对应的路径里,删掉这个文件,重新执行安装命令即可:
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"
2)若卡在了Cloning into...
由这里的龟速可断定卡住了,立马用Control + C中断脚本,然后执行以下命令:
cd "$(brew --repo)/Library/Taps/" mkdir homebrew && cd homebrew git clone git://mirrors.ustc.edu.cn/homebrew-core.git
执行后可看到:
速度立马快得飞起,一下子就能装好。
注:最后出现 Installation successful! 或者 Checking out files: 100% (5392/5392), done. 说明安装成功。
3.替换Homebrew 的安装源
brew、homebrew/core是必备项目,homebrew/cask、homebrew/bottles按需设置
1)必备设置
替换 brew.git:
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
替换 homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
2)按需设置
替换 homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
替换homebrew-bottles:
首先要先区分你的mac用哪种终端工具,如果是 bash,则执行:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile source ~/.bash_profile
若是 zsh,则执行:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc source ~/.zshrc
4. 基本用法
// 查询: brew search 软件名 // 安装: brew install 软件名 // 卸载: brew uninstall 软件名 // 更新 Homebrew: brew update // 查看 Homebrew 配置信息: brew config
5.卸载Homebrew
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall.sh)"