mac 安装nvm踩坑

安装nvm

安装之前如果有node环境的需要先卸载。
自己以前装过node,在安装nvm之前需要先卸载老的node,卸载过程可以参考这篇文章传送门

#查看已经安装在全局的模块
npm ls -g --depth=0
#删除全局 node_modules 目录
sudo rm -rf /usr/local/lib/node_modules
#删除 node
sudo rm /usr/local/bin/node
#删除全局 node 模块注册的软链
cd /usr/local/bin && ls -l | grep "../lib/node_modules/" | awk '{print $9}'| xargs rm

最后安装成功的案例:
可以参考官网进行安装官网传送门
1、第一次尝试执行
sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash 如果报错,就是ping不通raw.githubusercontent.com无法下载里面的文件
2、修改/etc/host 文件(这个后面自己又ping发现ping不通了,失败的话可以参考下面提供的ip查询网站进行修改host文件)

127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost
# 这个是修改后的 也是成功安装成功了
185.199.109.133 raw.githubusercontent.com

再次执行sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
如果失败看自己是不是 sudo执行,或者重新再执行一遍。
如果有以下显示就代表执行成功了。

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 14926  100 14926    0     0  15580      0 --:--:-- --:--:-- --:--:-- 15564
=> nvm is already installed in /Users/liuyuanyuan/.nvm, trying to update using git
* (HEAD detached at FETCH_HEAD)
  master
=> Compressing and cleaning up git repository

=> Appending nvm source string to /Users/liuyuanyuan/.bash_profile
=> Appending bash_completion source string to /Users/liuyuanyuan/.bash_profile
=> Close and reopen your terminal to start using nvm or run the following to use it now:

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

3、此时代表安装成功,执行nvm -v如果失败 执行以下 source ~/.bash_profile 注意一下,在执行之前先看下有没有该文件,我以前配置过其他东西,它在下载后就自动给我配置了,所以source一下即可。如果没有这个文件需要自己配置参考传送门

遇到的问题

1、一直报错:
curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443
分析:就是连接不上github网站,具体可以修改/etc/host文件参考一下传送门
2、报错过程中也修改了host文件还是失败,可能那个ip地址不行吧
最后成功的案例:
传送门
参考其他案例试试?
传送门1传送门2这个掘金文章里面修改host文件可以去指定网站查询ip,可以看一下,我成功了就没试这个

最后:主要是晚上下班后搞了好久,踩坑吧,遇到的问题大部分都是上面那个报错,下载nvm主要是管理node方便,因为vue项目拉下来别人的项目总是因为node版本过高,过低有问题,用nvm切换版本很轻松

猜你喜欢

转载自blog.csdn.net/qq_43566782/article/details/129747875