MacOS Catalina 如何安装 Homebrew

MacOS 版本

![os version](https://img-blog.csdnimg.cn/20200428215345747.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2x1Y2t5bWFuOTg=,size_16,color_FFFFFF,t_70#pic_center)

安装教程

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"

如果命令执行中卡在下面信息:

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

请Control + C中断脚本执行如下命令:

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 https://mirrors.ustc.edu.cn/homebrew-cask.git

卸载教程

/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"

设置镜像方法

brew、homebrew/core是必备项目,homebrew/cask、homebrew/bottles按需设置。

通过 brew config 命令查看配置信息。

中科大源
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
长期替换homebrew-bottles
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

注意bottles可以临时设置,在终端执行下面命令:

export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles

4.2 清华大学源

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
长期替换homebrew-bottles
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

4.3 恢复默认源

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

homebrew-bottles配置只能手动删除,将 ~/.bash_profile 文件中的 HOMEBREW_BOTTLE_DOMAIN=https://mirrors.xxx.com内容删除,并执行 source ~/.bash_profile。

其他

cask

目前cask是从GitHub上读取软件源,而GitHub Api对匿名访问有限制,如果使用比较频繁的话,可以申请Api Token,然后在环境变量中配置到HOMEBREW_GITHUB_API_TOKEN。

在.bash_profile中追加:

export HOMEBREW_GITHUB_API_TOKEN=yourtoken
注意:因为cask是基于GitHub下载软件,所以目前是无法加速的。

总结

在前面的过程中我们把brew和homebrew-core的地址都指向到中科大镜像。

原理是通过修改install脚本,在里面预设镜像地址来做到的。

#!/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere (which is
# unsupported) you can untar https://github.com/Homebrew/brew/tarball/master
# anywhere you like.
HOMEBREW_PREFIX = "/usr/local".freeze
HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
# 这里替换了BREW_REPO
BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git".freeze
最后不完美的地方是我们只能预设brew镜像,没找到比较好的办法预设homebrew-core、homebrew-cask的git地址。

来源

mac下镜像飞速安装Homebrew教程 - ineo6的文章 - 知乎

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值