原文链接:https://blog.csdn.net/sinat_38184748/article/details/99450330
macOS安装Homebrew太慢,换用清华镜像
前言
安装Homebrew
下载脚本
更换镜像源
成功
报错
验证检查
安装成功以后需要更换镜像源
完事
前言
毫无疑问,在mac下做开发,经常需要搭建一些环境需要用到Homebrew来下载。下面说一下我的经历。
安装Homebrew
Homebrew官网
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
1
将这个链接拷贝进终端,回车。
我挂着VPN下了半个小时,没下下来。。。又关了VPN,看着速度从25k变成了3k。。。
绝望。。。
下载脚本
后来百度了一下,看了别人的介绍。
解决国内 Mac 安装 brew 速度很慢问题
找到个脚本下载链接
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
1
但是下载下来的脚本里并没有该链接说的CORE_TAP_REPO这个词
接着找到了这个介绍:
Mac HomeBrew国内镜像安装方法
里面说:
注意: 新版本HomeBrew可能没有CORE_TAP_REPO这句代码,如果没有不用新增。 如果这个镜像有问题的话,可以换成其他源。
更换镜像源
上面两个介绍综合以后,我就高高兴兴去执行编辑后的脚本,却发现,还是没有下载下来。
后来又找到了下面这个介绍:
macOS 替换 Homebrew 的源为阿里云 & 清华的源
将镜像源修改成了清华的
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
1
2019-11-18 更新内容
或者使用中科大的镜像
路径:https://mirrors.ustc.edu.cn/brew.git
core:https://mirrors.ustc.edu.cn/homebrew-core.git
修改方法,就是打开下载的brew_install文件。
直接打开聚焦搜索,搜索即可
修改如下图位置内容:
#BREW_REPO = "https://github.com/Homebrew/brew".freeze
BREW_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git".freeze
1
2
接下来把修改好的文件拖到终端,还要在这前面加上sudo /usr/bin/ruby
具体如下:
sudo /usr/bin/ruby /Users/yangdilong/brew_install
1
或者直接
/usr/bin/ruby brew_install
1
回车,运行。。。
等待即可。。。
成功
==> Installation successful!
那就成功了,但是如果有报错,继续往下看。
报错
Warning: /usr/local/bin is not in your PATH.
==> Installation successful!
1
2
解决方案,终端输入,回车:
export PATH=/usr/local/bin:$PATH
1
修改成功后,就可以正常使用homebrew了。
但是,你会发现每次打开终端都需要输入一遍这玩意才能正常使用,太坑了。
所以要将这句代码添加到环境变量中去。
1、首先进入home目录
$ cd ~
1
2、创建.bash_profile文件
$ touch .bash_profile
1
3、打开.bash_profile文件,进行编辑
$ open -e .bash_profile
1
4、加入内容
export PATH=/usr/local/bin:$PATH
1
5、保存
使用 command + s
6、生效环境变量
$ source .bash_profile
1
以后就不需要每次打开终端都得输入一遍那玩意了。
验证检查
终端输入,回车:
brew -v
1
显示如下信息:
Homebrew 2.1.10
Homebrew/homebrew-core (git revision b7d38f; last commit 2019-08-12)
1
2
安装成功以后需要更换镜像源
2019-11-18 更新内容
替换现有上游
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
brew update
1
2
3
4
5
6
7
复原
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
brew update
1
2
3
4
5
6
7
完事
————————————————
版权声明:本文为CSDN博主「YD-10-NG」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sinat_38184748/article/details/99450330