最近在搞 JavaScripts,nodejs的版本满天飞,之前用的 nvm 管理的方法突然不能用了。

这里记录一下,比较新的 nvm 的安装使用方法:

下载安装:

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

以上的脚本安装到底做了什么呢?

一、它 clone 了 nvm 到 $HOME/.nvm目录

二、它在 .bashrc 中添加了三行

image-20211217093956358

事实上它是根据当前的 bash 选择在 .bash_profile、.zshrc、.profile、.bashrc中的某一个进行添加

然后我们退出终端,并重新进入,看看

nvm list
nvm ls-remote

然后选择最新的版本安装:

nvm install v16.13.1

如果想使用不同版本

nvm use 14.0.0

设置缺省版本或者取消

nvm alias defaut <your_nodejs_default_version>

nvm alias default 14.0.0
node -v # prints 14.0.0

参考地址:https://github.com/nvm-sh/nvm