安装说明
如果之前尝试过其他脚本安装,请移除Homebrew
后再安装,具体请参考 FAQ 。
<pre class="prism-code language-shell" style="box-sizing: border-box; font-size: 14px; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; margin: 0px; overflow: auto; color: rgb(0, 0, 0); background: transparent; text-shadow: rgb(255, 255, 255) 0px 1px; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 4; hyphens: none; padding: 1em;">
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
</pre>
默认使用中科大源,如果需要换源参考 换源。
如果命令执行中卡在下面信息:
<pre class="prism-code language-shell" style="box-sizing: border-box; font-size: 14px; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; margin: 0px; overflow: auto; color: rgb(0, 0, 0); background: transparent; text-shadow: rgb(255, 255, 255) 0px 1px; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 4; hyphens: none; padding: 1em;">
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
</pre>
请Control + C
中断脚本执行如下命令:
<pre class="prism-code language-shell" style="box-sizing: border-box; font-size: 14px; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; margin: 0px; overflow: auto; color: rgb(0, 0, 0); background: transparent; text-shadow: rgb(255, 255, 255) 0px 1px; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 4; hyphens: none; padding: 1em;">
cd "$(brew --repo)/Library/Taps/"
mkdir homebrew && cd homebrew
git clone git://mirrors.ustc.edu.cn/homebrew-core.git
</pre>
安装cask
同样也有安装失败或者卡住的问题,解决方法也是一样:
<pre class="prism-code language-shell" style="box-sizing: border-box; font-size: 14px; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; margin: 0px; overflow: auto; color: rgb(0, 0, 0); background: transparent; text-shadow: rgb(255, 255, 255) 0px 1px; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 4; hyphens: none; padding: 1em;">
cd "$(brew --repo)/Library/Taps/"
cd homebrew
git clone https://mirrors.ustc.edu.cn/homebrew-cask.git
</pre>
成功执行之后继续执行安装命令。
最后看到==> Installation successful!
就说明安装成功了。
最最后更新下:
<pre class="prism-code language-shell" style="box-sizing: border-box; font-size: 14px; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; margin: 0px; overflow: auto; color: rgb(0, 0, 0); background: transparent; text-shadow: rgb(255, 255, 255) 0px 1px; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 4; hyphens: none; padding: 1em;">
brew update
</pre>
设置镜像
更新:强烈建议使用 镜像助手 ,你可以自助获取镜像脚本,目前支持中科大、清华、腾讯、北京外国语镜像源。
中科大源
<pre class="prism-code language-shell" style="box-sizing: border-box; font-size: 14px; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; margin: 0px; overflow: auto; color: rgb(0, 0, 0); background: transparent; text-shadow: rgb(255, 255, 255) 0px 1px; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 4; hyphens: none; padding: 1em;">
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
brew update
</pre>
清华大学源
<pre class="prism-code language-shell" style="box-sizing: border-box; font-size: 14px; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; margin: 0px; overflow: auto; color: rgb(0, 0, 0); background: transparent; text-shadow: rgb(255, 255, 255) 0px 1px; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 4; hyphens: none; padding: 1em;">
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
brew update
</pre>
设置 bottles 镜像
设置环境变量需要注意终端的类型,可以先通过以下方式获取:
执行命令echo $SHELL
,根据结果判断:
-
/bin/zsh
=>zsh
=>.zprofile
-
/bin/bash
=>bash
=>.bash_profile
然后继续正式操作,以中科大源为例:
从macOS Catalina
(10.15.x) 版开始,Mac
使用zsh
作为默认Shell
,对应文件是.zprofile
,所以命令为:
<pre class="prism-code language-shell" style="box-sizing: border-box; font-size: 14px; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; margin: 0px; overflow: auto; color: rgb(0, 0, 0); background: transparent; text-shadow: rgb(255, 255, 255) 0px 1px; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 4; hyphens: none; padding: 1em;">
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.zprofile
source ~/.zprofile
</pre>
如果是macOS Mojave
及更低版本,并且没有自己配置过zsh
,对应文件则是.bash_profile
:
<pre class="prism-code language-shell" style="box-sizing: border-box; font-size: 14px; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; margin: 0px; overflow: auto; color: rgb(0, 0, 0); background: transparent; text-shadow: rgb(255, 255, 255) 0px 1px; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 4; hyphens: none; padding: 1em;">
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile
source ~/.bash_profile
</pre>
注意:上述区别仅仅是
.zprofile
和.bash_profile
不同,上下文如有再次提及编辑.zprofile
,均按此方法判断具体操作的文件。
至此,安装和设置操作都完成了。
恢复默认源
<pre class="prism-code language-shell" style="box-sizing: border-box; font-size: 14px; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; margin: 0px; overflow: auto; color: rgb(0, 0, 0); background: transparent; text-shadow: rgb(255, 255, 255) 0px 1px; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 4; hyphens: none; padding: 1em;">
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
brew update
</pre>
homebrew-bottles
配置只能手动删除,将 ~/.zprofile
文件中的 HOMEBREW_BOTTLE_DOMAIN=https://mirrors.xxx.com
内容删除,并执行 source ~/.zprofile
。
如何卸载 Homebrew
使用官方脚本同样会遇到uninstall
地址无法访问问题,可以使用下面脚本:
<pre class="prism-code language-shell" style="box-sizing: border-box; font-size: 14px; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; margin: 0px; overflow: auto; color: rgb(0, 0, 0); background: transparent; text-shadow: rgb(255, 255, 255) 0px 1px; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 4; hyphens: none; padding: 1em;">
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall.sh)"
</pre>
其他相关
cask
目前cask
是从GitHub
上读取软件源,而GitHub Api
对访问有限制,如果使用比较频繁的话,可以申请Api Token
,然后在环境变量中配置到HOMEBREW_GITHUB_API_TOKEN
。
在.zprofile
中追加,注意替换yourtoken
:
<pre class="prism-code language-shell" style="box-sizing: border-box; font-size: 14px; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; margin: 0px; overflow: auto; color: rgb(0, 0, 0); background: transparent; text-shadow: rgb(255, 255, 255) 0px 1px; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 4; hyphens: none; padding: 1em;">
echo 'export HOMEBREW_GITHUB_API_TOKEN=yourtoken' >> ~/.zprofile
source ~/.zprofile
</pre>
注意:因为cask
是从GitHub
下载软件,所以目前是无法加速的。