root 权限
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.bashrc
非root权限
cd ~ && git clone https://github.com/nvm-sh/nvm.git .nvm
cd ~/.nvm && git checkout v0.40.1
手动添加环境变量
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
简单使用
nvm ls-remote # 查看可用的node版本列表
nvm install vv20.18.1 # 安装指定版本的node
nvm use vv20.18.1 # 切换到指定版本的node
nvm uninstall vv20.18.1 # 卸载指定版本的node