# 下载并安装nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
# 添加环境变量
\. "$HOME/.nvm/nvm.sh"
# 下载并安装合适版本的 Node.js:
nvm install 24
# Verify the Node.js version:
node -v
# Verify npm version:
npm -v
若要更新版本,使用nvm安装最新版即可
常用指令
nvm --version
nvm install [] --lts --latest-npm --save --default
nvm uninstall
nvm use []
nvm current
nvm ls []
nvm unload
nvm which [current | ]
指令argument介绍
--latest-npm After installing, attempt to upgrade to the latest working npm on the given node version
--save After installing, write the specified version to .nvmrc
--default After installing, set default alias to the version specified. (same as: nvm alias default \)
用例
nvm install 8.0.0 Install a specific version number
nvm use 8.0 Use the latest available 8.0.x release
nvm run 6.10.3 app.js Run app.js using node 6.10.3
nvm exec 4.8.3 node app.js Run `node app.js` with the PATH pointing to node 4.8.3
nvm alias default 8.1.0 Set default node version on a shell
nvm alias default node Always default to the latest available node version on a shell
nvm install node Install the latest available version
nvm use node Use the latest version
nvm install --lts Install the latest LTS version
nvm use --lts Use the latest LTS version
Note:
to remove, delete, or uninstall nvm - just remove the $NVM_DIR folder (usually ~/.nvm)

Comments NOTHING