WLOP | 北漠
260 words
1 minute
Mac Homebrew 国内镜像源替换或重置
Homebrew 安装
Homebrew是一款包管理工具,目前支持macOS和linux系统。安装方式很简单,将下面👇命令复制到命令行终端运行即可。
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"查看当前Homebrew 镜像源
# brew.git镜像源git -C "$(brew --repo)" remote -v
# homebrew-core.git镜像源git -C "$(brew --repo homebrew/core)" remote -v
# homebrew-cask.git镜像源git -C "$(brew --repo homebrew/cask)" remote -vHomebrew 换源(科大):
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
if [ $SHELL = "/bin/bash" ] # 如果你的是bashthen echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/' >> ~/.bash_profile source ~/.bash_profileelif [ $SHELL = "/bin/zsh" ] # 如果用的shell 是zsh 的话then echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/' >> ~/.zshrc source ~/.zshrcfi
brew update恢复原有镜像源(国内镜像源突然不能用了或版本不够新)
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
# 找到 ~/.bash_profile 或者 ~/.zshrc 中的HOMEBREW_BOTTLE_DOMAIN 一行删除
brew updateHomebrew 重置
brew doctorbrew update-resetbrew update参考链接
Mac Homebrew 国内镜像源替换或重置
https://evanyuki.github.io/posts/c507e0a3c99a470da92c5366ef2bcb8e/