# 2021-01-03 #「NVM」- Node Version Manager(在本地安装多版本 Node.js 环境)
NVM,用于在系统中安装多个版本 Node.js 环境,并可以自如切换。
在 Linux 中,安装 nvm 工具
Debian GNU/Linux 10 (buster) and Bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
cat >> ~/.bashrc <<EOF
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
EOF
使用 nvm 安装 Node.js 环境
node.js - Where is node while using nvm? - Stack Overflow
// 查看所有可用的 13 版本
# nvm list-remote v13.10
v13.10.0
v13.10.1
// 安装 v13.10.1 版本
# nvm install v13.10.1
Downloading and installing node v13.10.1...
Downloading https://nodejs.org/dist/v13.10.1/node-v13.10.1-linux-x64.tar.xz...
####################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v13.10.1 (npm v6.13.7)
// 切换到 v13.10.1 版本,或者使用系统版本
nvm use v13.10.1
nvm use system
nvm alias default system # 设置默认版本(命令 nvm use 只设置当前终端)
// 显示当前正在使用 node 命令的路径
# nvm which $(nvm current)
/usr/bin/node
卸载 npm 工具
npm - How do I modify the configuration of Yarn? - Stack Overflow
removal | npm Docs
npm uninstall npm -g
rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*
常用命令汇总
查看所有可以安装的版本
How to list all available node.js versions? · Issue #84 · nvm-sh/nvm · GitHub
nvm ls-remote
常见问题汇总(FAQ)
相关链接
参考文献
K4NZ/Node Version Manager(在本地安装多版本 Node.js 环境)
node.js - How can the default node version be set using NVM? - Stack Overflow
浙公网安备 33010602011771号