Mac OS Homebrew更换国内镜像源(中科大;阿里;清华)

omebrew官方的源一般下载包之类的会很慢,所以通常我们都是用国内的镜像源来代替,这样会提高我们的效率。Homebrew主要有四个部分组成: brew、homebrew-core 、homebrew-bottles、homebrew-cask。

代码语言:javascript

代码运行次数:0

复制

Cloud Studio代码运行

复制代码
名称                    说明
brew            Homebrew 源代码仓库
homebrew-core    Homebrew 核心软件仓库
homebrew-bottles    Homebrew 预编译二进制软件包
homebrew-cask    MacOS 客户端应用

Homebrew国内镜像源目前主要有中科大镜像、阿里镜像、清华镜像。 首先查看自己本地的镜像源地址是什么,在命令行输入以下命令可以查询:

1.查看 brew.git 当前源:

代码语言:javascript

代码运行次数:0

复制

Cloud Studio代码运行

复制代码
cd "$(brew --repo)" && git remote -v
结果:
origin  https://mirrors.ustc.edu.cn/brew.git (fetch)
origin  https://mirrors.ustc.edu.cn/brew.git (push)

2.查看 homebrew-core.git 当前源

代码语言:javascript

代码运行次数:0

复制

Cloud Studio代码运行

复制代码
cd "$(brew --repo homebrew/core)" && git remote -v
结果:
origin  https://mirrors.ustc.edu.cn/homebrew-core.git (fetch)
origin  https://mirrors.ustc.edu.cn/homebrew-core.git (push)

这是我更换了的镜像源,如果没更换,提示如下:

代码语言:javascript

代码运行次数:0

复制

Cloud Studio代码运行

复制代码
1.查看 brew.git 当前源输出
origin    https://github.com/Homebrew/brew.git (fetch)
origin    https://github.com/Homebrew/brew.git (push)
2.查看 homebrew-core.git 当前源输出
origin    https://github.com/Homebrew/homebrew-core.git (fetch)
origin    https://github.com/Homebrew/homebrew-core.git (push)

如果是Github的,这里建议更换: 切换 Homebrew 镜像源为中科大镜像源

代码语言:javascript

代码运行次数:0

复制

Cloud Studio代码运行

复制代码
1.替换brew.git:
cd "$(brew --repo)" && git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
2.替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" 
&& git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
3.替换homebrew-cask.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask" 
&& git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git

zsh 替换homebrew-bottles镜像,Mac OS在10.15系统开始,默认的shell都换成了zsh

代码语言:javascript

代码运行次数:0

复制

Cloud Studio代码运行

复制代码
echo 'export HOMEBREW_BOTTLE_DOMAIN=
https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc

修改使其立即生效:

代码语言:javascript

代码运行次数:0

复制

Cloud Studio代码运行

复制代码
source ~/.zshrc

bash 替换homebrew-bottles镜像

代码语言:javascript

代码运行次数:0

复制

Cloud Studio代码运行

复制代码
echo 'export HOMEBREW_BOTTLE_DOMAIN=
https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile

修改使其立即生效:

代码语言:javascript

代码运行次数:0

复制

Cloud Studio代码运行

复制代码
brew update

这里还可以替换成其他的源,比如阿里,清华等。 如果要换回官方镜像源,可以如下操作;

代码语言:javascript

代码运行次数:0

复制

Cloud Studio代码运行

复制代码
1.重置 brew.git 为官方源:
cd "$(brew --repo)" && git remote set-url origin https://github.com/Homebrew/brew.git
2.重置 homebrew-core.git 为官方源:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && git remote set-url origin https://github.com/Homebrew/homebrew-core.git
3.重置 homebrew-cask.git 为官方源:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
&& git remote set-url origin https://github.com/Homebrew/homebrew-cask
4.zsh 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置,前面加#符号就行
vi ~/.zshrc
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
5.修改使其立即生效
source ~/.zshrc
6.刷新源
brew update
相关推荐
fengyun28912 天前
fcpx音视频剪辑编辑 Final Cut Pro X(Mac电脑)
macos·mac
伊成2 天前
Mac中如何Chrome禁用更新[update chflags macos]
chrome·mac
fengyun28912 天前
Mac电脑 虚拟机 VMware Fusion13
macos·mac·虚拟机
2401_8885670013 天前
Mac电脑-媒体文件格式转换-Permute
macos·mac·媒体·格式转换
2501_9205525614 天前
Mac电脑-音视频剪辑编辑-Final Cut Pro X(fcpx)
macos·音视频·mac
Bar_artist14 天前
键盘觉醒:Raycast 把 Mac 变成「AI 指令战舰」
人工智能·mac·wwdc·raycast
2401_8885670014 天前
Mac电脑 窗口分屏管理 Magnet Pro
macos·mac·分屏
伊织code15 天前
macOS - 根据序列号查看机型、保障信息
macos·mac·macbook·查看·序列号·机型·对应
iChochy15 天前
[开源自荐]AI Chat 智能聊天工具,支持DeepSeek 、Gemini、Grok、OpenAI和自定义AI
app·openai·mac·deepseek
90后的晨仔15 天前
pod报错:uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger (NameE
ios·mac