Homebrew安装、换源。


前言

提示:这里可以添加本文要记录的大概内容:
Homebrew 是一个MacOS 上的包管理器,你可以用它来安装管理软件,功能非常强大,基本上只要是MacOS上能安装的软件,你通过Homebrew 都能够安装。类似于Linux上的yum,或者nodejs的npm。


提示:以下是本篇文章正文内容,下面案例可供参考

一、什么是Homebrew的源?

其实就是一个git的url,对应的是git仓库。
每次通过Homebrew安装软件,Homebrew会根据源,会比对、下载(或者merge)源仓库到本地,然后根据要下载的软件找到对应的xxx.rb文件,然后再根据rb文件中内容一步步的校验、下载、安装软件。

1.Homebrew原始源

代码如下(示例):

# homebrew
https://github.com/Homebrew/brew.git
# homebrew-core源
https://github.com/Homebrew/homebrew-core.git
# homebrew-cask源
https://github.com/Homebrew/homebrew-cask.git

二、替换Homebrew的源

1.替换为清华的源

代码如下(示例):

# 替换brew.git源
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替换 homebrew-core.git源
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# 替换 homebrew-cask.git源
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

其实替换这三个源就可以了,另外就是homebrew-bottles,这个配置个HOMEBREW_BOTTLE_DOMAIN环境变量,不过好像不配置也没啥问题:

# 使用bash的话
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

# 使用zsh的话
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

2.替换为中科大的源

代码如下(示例):

# 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
# homebrew-cask.git源
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.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

3.复核与还原

如果想重置为官方的源,可以如下操作:

# brew.git源
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
# homebrew-core.git源
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core
# homebrew-cask.git源
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask
//最后执行brew update来尝试一下看是否速度更快。

如果想重置为官方的源,可以如下操作:

# brew.git源
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
# homebrew-core.git源
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core
# homebrew-cask.git源
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask
//另外记住删除 HOMEBREW_BOTTLE_DOMAIN 环境变量
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值