1. 检查电脑上是否安装了node, node -v,有的话先卸载,卸载完成后再 node -v 检查一下,可以参考mac卸载node
    在不卸载node和清除cache的情况下安装nvm会出现其他报错
  2. 清除node的chche
 sudo npm cache clean -f

3.安装nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

出现报错:Failed to connect to raw.githubusercontent.com port 443,couldn’t find the server,无法连接到服务器
然后打开 https://www.ipaddress.com/ 将raw.githubusercontent.com输入右上角搜索框,下拉找到ip
在这里插入图片描述
4. 终端输入sudo vim /etc/hosts 编辑hosts文件,将这行添加到hosts文件中,:wq保存。

185.199.108.133   raw.githubusercontent.com

在这里插入图片描述
此时下载很可能还会报错,切换成手机热点后,就可以成功下载了
4.在终端中输入

 touch .dash_profile // 创建dash_profile文件
 open .dash_profile // 打开dash_profile文件

将下面内容填加进去

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

在这里插入图片描述
5.执行命令nvm -v检查一下是否安装成功,如果依旧是command not found,退出终端重新执行 nvm -v ,可以看到已经安装成功。
6.然后执行 nvm install 版本号 就可以下载指定版本的node了。

参考文章:https://blog.csdn.net/qq_54956455/article/details/130387143
https://blog.csdn.net/qq_42454107/article/details/136781013
https://blog.csdn.net/qq_34629527/article/details/137756545

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐