Homebrew配置所在目录
Homebrew的配置分成三个目录,分别是
1、brew(brew --repo
)
2、homebrew/core(brew --repo homebrew/core
)
3、homebrew/cask(brew --repo homebrew/cask
)
Homebrew查看源配置
在目录中可以通过git remote get-url origin来查看当前的源的URL。
git -C “$(brew –repo)” remote get-url origin
git -C “$(brew –repo homebrew/core)” remote get-url origin
git -C “$(brew –repo homebrew/cask)” remote get-url origin
(base) MacBook-Air:~ root$ git -C “$(brew –repo)” remote get-url origin
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
(base) MacBook-Air:~ root$ git -C “$(brew –repo homebrew/core)” remote get-url origin
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
(base) MacBook-Air:~ root$ git -C “$(brew –repo homebrew/cask)” remote get-url origin
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
Homebrew修改源配置
方法1:
export HOMEBREW_BREW_GIT_REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
export HOMEBREW_CORE_GIT_REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
方法2:
#注:可以通过以下命令设置为默认值,最后需要更新
#设置为清华源
# brew 程序本身,Homebrew/Linuxbrew 相同
git -C “$(brew –repo)” remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 以下针对 mac OS 系统上的 Homebrew
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
git -C “$(brew –repo homebrew/cask-fonts)” remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git -C “$(brew –repo homebrew/cask-drivers)” remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
#设置为github源
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
brew update
替换后可以通过以下指令输出的ORIGIN项来观察是否已经修改完成:
brew --config HOMEBREW_VERSION: 2.5.6 ORIGIN: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git HEAD: abf214c01ff1edb57acf7e23d5eb24a777335e11
2种方法的区别
这两种操作都是为了修改 Homebrew 的 Git 仓库的远程 URL,以便让 Homebrew 使用不同的数据源或镜像。它们的区别在于实现方式和影响范围。
- 使用
export HOMEBREW_XXXX_GIT_REMOTE
的方式:- 这种方式是通过设置环境变量的方式告知 Homebrew 使用指定的 Git 仓库作为数据源。
export HOMEBREW_BREW_GIT_REMOTE
和export HOMEBREW_CORE_GIT_REMOTE
分别设置了 Homebrew 的brew
和homebrew-core
仓库的远程 URL。- 这种方式会全局地影响 Homebrew 的仓库使用,因此所有的操作都会使用指定的镜像源。
- 通过 brew –config 可以查看到配置的变量
- 使用
git -C "$(brew --repo XXXX)" remote set-url origin
的方式:- 这种方式是直接通过 Git 命令修改 Homebrew 中各个仓库的远程 URL。
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
这个命令会修改homebrew/core
仓库的远程 URL。- 这种方式是在特定的仓库上设置新的远程 URL,而不是全局影响。
这两种方式的结果都是为 Homebrew 指定了新的数据源,让它可以从指定的镜像站获取更新和信息。选择哪种方式取决于您的需求和偏好:全局影响或仅特定仓库的修改。
建议使用第1种方式,否则brew update时还是会通过github