mac上安装npm-通过清华镜像安装Homebrew经验总结

2022-06-15 08:25:28

一、终端输入brew -v

brew -v

终端返回
zsh: command not found: brew

二、安装homeview,

点击此处跳转到Homeview

终端输入命令

/usr/bin/ruby -e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

后面就开始下载,但是速度超级慢,慢就算了

2000 years later…

还报错了,以下是报错信息截取
在这里插入图片描述

三、解决Failed during: git fetch origin master:refs/remotes/origin/master --tags --force

1、终端输入命令

ping github.com

返回
在这里插入图片描述

这个亚子是不通的,按control+C停止

2、修改host配置文件

终端输入命令

sudovi /etc/hosts

最下面加一行

192.30.253.113 github.com

在这里插入图片描述
保存
然后再ping
终端输入命令

ping github.com

然后通了,返回
在这里插入图片描述
按control+C停止

参考的博文到这里可以正常安装了,可是对于我来说,坎坷的路才走了一小半
我开心又天真了进行了下一步

在终端输入命令

ruby -e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

于是,我迎来了一个新的挑战
终端返回
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

此时我强忍住心中的怒火,继续百度。

四、解决curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

1、根据百度的答案(相关参考的链接后面都写了)

在浏览器输入
https://raw.githubusercontent.com/Homebrew/install/master/install

好的,打不开。。。
原文认为这个是网络的问题,但是我不是公司网,是家里的网耶,于是我切换成了自己手机的热点,然后就意外的打开了,是这个亚子的
在这里插入图片描述

这个网页内容需要保存下来
过了一会又打不开了,并不稳定

2、把这个网页保存名为brew_install.rb的文件,位置随意

打不开的朋友请不要着急,这个即使保存了还要改东西的,我们标题是通过清华镜像安装,是吧?我还没说到呢。
一会我会把改好的文件分享出来。
重要的并不是这个文件,而是我正在分享的这段坑爹的经历。

3、终端输入命令

curl

终端返回
curl: try ‘curl --help’ or ‘curl --manual’ for more information

这个命令没有什么实际的作用,只是检查一下连接性。

4、终端输入命令

ruby brew_install.rb

原文博主在这个地方就顺利结束了。但是对于我来说,坎坷的路才走了大概一半吧。

终端返回
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew

…(太长了省略)

HEAD is now at 5b126ec85 Merge pull request #7055 from MikeMcQuaid/no-more-actions-spam

最后就卡在上面这段话,停了好久,真的好烦,于是我按了
control+C停止了

5、终端输入命令

 brew -v

看看安装成功没
终端返回
Homebrew 2.2.6-18-g5b126ec
Homebrew/homebrew-core N/A

我敏锐的感觉我有什么东西没下完整

6、终端输入命令

brewinstall node

终端返回
Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core’…

在这里停了大概半个小时吧,一点反应都没,给我气的想砸电脑,
可是我怎么舍得我这新买的16英寸的mac pro?

好了,终于到了通过清华镜像安装Homebrew阶段

五、通过清华镜像安装Homebrew

1、刚才保存的那个brew_install.rb文件,改个镜像

原来是
BREW_REPO = “https://github.com/Homebrew/brew”.freeze
改成
BREW_REPO = “https://mirrors.ustc.edu.cn/brew.git”.freeze
原文还要改个链接,我加了还报错就没加了,这个也行的

打不开的同学可以在这里下载,因为这个文件还需要用UTF-8编码,不然也是会报错的~

链接: https://pan.baidu.com/s/1fl_LyTOgvWHkur5dl6YYLw 提取码: 5xjp

或者下载这个也可以
https://download.csdn.net/download/Yolanda_NuoNuo/12175566
下载这个我还有分拿,嘻嘻~

2、cd 到brew_install.rb文件位置

终端输入命令

ruby brew_install.rb

顺利装了一会终端又出现了这个
Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core’…

恐怖😱
不怕!control+C停止

3、终端输入命令

git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

终端顺利返回
在这里插入图片描述

炒鸡开心!

4、终端有序输入以下四个命令

cd"$(brew --repo)"git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.gitcd"$(brew --repo)/Library/Taps/homebrew/homebrew-core"git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

5、终端输入命令

brew update

终端返回
Already up-to-date.

哇哦,看这个亚子胜利已经不远了。

6、终端输入命令

brew doctor

检查一下安装的对不对

终端返回
在这里插入图片描述

哇哦,有警告
不管它!忽视!

7、终端输入命令

brew -v

终端返回
Homebrew 2.2.6
Homebrew/homebrew-core (git revision ec2a; last commit 2020-02-20)

8、终于来到尾声,可以安装啦!

终端输入命令

brewinstall node

终端返回
在这里插入图片描述

这个地方要等好久,建议去吃个饭~

9、终端输入命令

npm -v

终端返回
在这里插入图片描述

好啦!终于成功啦!

此篇参考了以下博文,根据自己的情况进行了整理,感谢对我的帮助!
https://blog.csdn.net/pangjiaming99/article/details/84557813
https://www.cnblogs.com/divebombchen/p/10491844.html
https://www.jianshu.com/p/68efabd2e32b
https://blog.csdn.net/qq_35624642/article/details/79682979

  • 作者:Yolanda_NuoNuo
  • 原文链接:https://blog.csdn.net/Yolanda_NuoNuo/article/details/104415750
    更新时间:2022-06-15 08:25:28