macOS安装brew
Posted 自在拉基
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了macOS安装brew相关的知识,希望对你有一定的参考价值。
配置
设置hosts
因为不设置hosts无法解析过去,步骤如下
打开 「 终端 」
ping raw.githubusercontent.com #看返回值
PING raw.githubusercontent.com (151.101.8.133): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
#返回值是 151.101.8.133 ,记一下这个IP
vim /etc/hosts
# 末尾加入一行
raw.githubusercontent.com
#保存退出
10.15版本需要关闭SIP
查看
关闭SIP是否安全暂不讨论,有兴趣的可以去查一下相关文档
csrutil status #查看一下当前SIP状态
System Integrity Protection status: enabled. #属于未关闭状态
关闭
关机或重启,按住Command + R 进入恢复模式,打开 「终端」输入以下命令,重启
csrutil disable #关闭SIP
安装
下载脚本
打开下载器下载脚本,如NDM
在弹出的框里输入 链接
https://raw.githubusercontent.com/Homebrew/install/master/install.sh
然后下载
修改脚本
可忽略,只是为了加速克隆速度,这里使用的是清华大学的镜像站。
打开下载的脚本,将脚本里的:
BREW_REPO="https://github.com/Homebrew/brew"
# 变成:
BREW_REPO="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
保存退出,然后运行一下脚本。
HOMEBREW_CORE_GIT_REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git bash install.sh
测试
等脚本跑完之后可通过
brew update
或者brew -v
看一下是否安装正常,如下图:
然后,
brew install wget
安装 wget工具试试是否可正常安装,如可以,恭喜你已经成功安装完毕了。到这一步你就可以重启,然后重新打开 SIP 功能了。
别急,还有!
有没有发现下载的时候很慢,由于国内网络的问题GitHub下载速度有所限制,那么接下来我就来教大家怎么配置国内的安装源,让安装的速度更快。
替换之前需要在homebrew目录下创建一下图中几个文件夹:
替换brew
阿里的镜像
cd "$(brew --repo)"
git remote set-url originhttps://mirrors.aliyun.com/homebrew/brew.git
替换brew-core
阿里的镜像
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url originhttps://mirrors.aliyun.com/homebrew/homebrew-core.git
替换brew-bottles
阿里的镜像
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
替换brew-cask
USTC镜像
cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
git remote set-url originhttps://mirrors.ustc.edu.cn/homebrew-cask.git
结束!
完
点分享
点点赞
点在看
以上是关于macOS安装brew的主要内容,如果未能解决你的问题,请参考以下文章