HomeBrew 安装

HomeBrew中文地址

通过以上链接把安装地址拿到, 这个地址可能会变, 再次使用需要重新获取:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装方式

命令行安装

如果网络畅通, 直接在命令行执行上面的命令即可.

手动下载安装

如果网络比较卡的情况, 比如我的网, 那就需要使用手动下载方式安装.

下载 install 文件

在浏览器中打开 https://raw.githubusercontent.com/Homebrew/install/master/install 这一段, 然后保存到本地为 install.rb 文件.

替换 BREW_REPO 镜像地址

替换 install.rbBREW_REPO 为中科大的源, 这里注释掉, 然后重新添加一行.

#BREW_REPO = "https://github.com/Homebrew/brew".freeze
BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git".freeze

然后在命令行执行 ruby install.rb , 注意这里目录要切换到 install.rb 所在目录, 然后就会看到

$ ruby install.rb 
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/Homebrew

Press RETURN to continue or any other key to abort

然后回车继续执行, 一顿操作之后, 执行下面这里时会卡住:

==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...

网比较卡的情况这里会执行失败, 我们就不等了, 直接 ctrl + c 结束命令.

然后我们在命令行输入以下命令:

git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

这个命令是从中科大的源去下载 homebrew-core

Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 5032, done.
remote: Compressing objects: 100% (4835/4835), done.
remote: Total 5032 (delta 49), reused 721 (delta 6)
Receiving objects: 100% (5032/5032), 4.03 MiB | 2.49 MiB/s, done.
Resolving deltas: 100% (49/49), done.
Checking out files: 100% (5050/5050), done.

到这里 HomeBrew 算是安装完成了.

源设置

安装完成还需要设置源, 设置完源我们使用才能更顺畅. 至于为啥要设置这么多源, 以及这些个源的作用, 请参考文末的引用链接.

替换brew.git:

cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

替换homebrew-core.git:

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

Homebrew Bottles源设置:

对于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

中科大源设置参考链接

brew,brew-core,brew-bottles是啥这篇讲的比较清楚

macOS 包管理工具 Homebrew 不完全指南

参考链接(这篇写的有点凌乱,所以我才自己写了一篇)

猜你喜欢

转载自www.cnblogs.com/haha1212/p/11271255.html