注意: mac安装nvm首先一定要确定本机中是否已经安装了nvm 和 node,参考本教程之前请先卸载。
1、打开终端,进入系统更目录: cd
2、在根目录文件下配置 .dash_profile,
touch .dash_profile
open .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
3、在根目录执行命令:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
4、安装完成之后一定要退出终端重新打开才能生效。
如图:
注意:以上步骤请一定按照顺序执行。
常见问题
1、若出现 每次打开终端,nvm都是使用默认的node版本,而非上次使用的node版本,则需要重置mac 默认版本,依次输入以下命令,重新打开终端即可。
nvm alias default 版本
nvm use 版本
2、安装时报错 curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused 通过终端查询IP地址
ping raw.githubusercontent.com
在终端输入sudo vi /etc/hosts 在最后添加 185.199.108.133 raw.githubusercontent.com 保存后退出重新运行安装命令
输入i 进入编辑模式
esc 退出编辑
:wq 保存退出