将 Homebrew 切换成国内的源可以显著提高软件包的下载速度。以下是详细步骤,帮助你将 Homebrew 的主仓库和核心仓库切换到国内镜像源。这里以中国科学技术大学(USTC)的镜像源为例,其他镜像源的切换方法类似。
切换 Homebrew 主仓库
-
打开终端。
-
切换 Homebrew 主仓库到 USTC 镜像:
cd "$(brew --repo)" && git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
-
验证是否切换成功:
cd "$(brew --repo)" && git remote -v
切换 Homebrew 核心仓库
-
切换 Homebrew 核心仓库到 USTC 镜像:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
-
验证是否切换成功:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && git remote -v
切换 Homebrew Cask 仓库
-
切换 Homebrew Cask 仓库到 USTC 镜像:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" && git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
-
验证是否切换成功:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" && git remote -v
其他常用的国内镜像源
除了中国科学技术大学(USTC)提供的镜像外,还有其他一些常用的国内镜像源:
-
清华大学:
- Homebrew 主仓库:
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
- Homebrew 核心仓库:
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
- Homebrew Cask 仓库:
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
- Homebrew 主仓库:
-
北京大学:
- Homebrew 主仓库:
https://mirrors.pku.edu.cn/homebrew/brew.git
- Homebrew 核心仓库:
https://mirrors.pku.edu.cn/homebrew/homebrew-core.git
- Homebrew Cask 仓库:
https://mirrors.pku.edu.cn/homebrew/homebrew-cask.git
- Homebrew 主仓库:
-
阿里云:
- Homebrew 主仓库:
https://mirrors.aliyun.com/homebrew/brew.git
- Homebrew 核心仓库:
https://mirrors.aliyun.com/homebrew/homebrew-core.git
- Homebrew Cask 仓库:
https://mirrors.aliyun.com/homebrew/homebrew-cask.git
- Homebrew 主仓库:
恢复默认源
如果你需要恢复到 Homebrew 的默认源,可以使用以下命令:
-
恢复 Homebrew 主仓库:
cd "$(brew --repo)" && git remote set-url origin https://github.com/Homebrew/brew
-
恢复 Homebrew 核心仓库:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && git remote set-url origin https://github.com/Homebrew/homebrew-core
-
恢复 Homebrew Cask 仓库:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" && git remote set-url origin https://github.com/Homebrew/homebrew-cask