homebrew 换源
时间: 2025-01-12 08:46:47 浏览: 62
### 更改 Homebrew 镜像源
为了提高在中国大陆地区使用 Homebrew 的效率,可以将默认的镜像源更改为国内的镜像源。这可以通过修改 Git 远程仓库地址以及 Homebrew 自身的一些设置来实现。
#### 修改 Homebrew 主库和核心库的远程 URL 地址
对于已经安装过 Homebrew 的用户来说,先切换到主目录下的 `.git` 文件夹中找到 `config` 文件并备份它:
```bash
cd $(brew --repo)/.git/
cp config config.bak
```
接着执行如下命令以替换为清华大学提供的镜像源[^2]:
```bash
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
```
同样的操作也适用于 Homebrew/core 和其他 taps(插件),比如 Homebrew/cask:
```bash
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
```
#### 更新本地缓存
完成上述更改之后,建议清理旧版本的软件包数据,并更新 Homebrew 列表以便立即生效新的配置:
```bash
brew update
brew cleanup
```
通过以上步骤就可以成功地把 Homebrew 及其依赖项指向更快捷稳定的国内服务器了[^4]。
阅读全文
相关推荐


















