Homebrew安装、换源

2022年7月10日11:13:48

前言

提示:这里可以添加本文要记录的大概内容:
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 环境变量
  • 作者:ffy-小王
  • 原文链接:https://blog.csdn.net/axiaofeijia/article/details/124036960
    更新时间:2022年7月10日11:13:48 ,共 2626 字。