一、Homebrew是什么
Homebrew
Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷。
援引官方的一句话:又提示缺少套件啦?别担心,Homebrew 随时守候。Homebrew —— OS X 不可或缺的套件管理器。
二、Homebrew安装
按照命令安装
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
报错
加权限
sudo chgrp -R admin /usr/local
sudo chmod -R g+w /usr/local
再次安装
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安装成功
三、修改镜像源
查看镜像源
查看当前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 -v
国内镜像地址
科大: https://mirrors.ustc.edu.cn
阿里: https://mirrors.aliyun.com/homebrew/
科大真香实例:
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
修改环境变量
vi /etc/profile
//在最下面添加
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/
//更新
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
删除/etc/profile环境变量中HOMEBREW_BOTTLE_DOMAIN
brew update
如果可以了下面的就不用看了
如果不行的话可以依次尝试以下命令
brew doctor
brew update-reset
brew update
参考地址
中文官网地址:https://brew.sh/index_zh-cn.html
修改镜像:https://zhuanlan.zhihu.com/p/102760018