Skip to content

Ubuntu安装nvm ​

执行安装脚本 ​

bash
sudo apt install curl 
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

环境变量生效 ​

bash
source ~/.bashrc

检验是否安装成功 ​

bash
nvm -v

使用说明 ​

bash
Example:
  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

  nvm set-colors cgYmW                  Set text colors to cyan, green, bold yellow, magenta, and white

Note:
  to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)

示例 ​

比如:我要使用20.18.0

bash
nvm install 20.18.0

查看当前所使用的版本:

bash
node -v 
v20.18.0

永久默认 ​

使用的过程中我发现,使用以下命令后,只能临时有效。重新打开新的终端版本又变回原来的了。

bash
nvm use 12.22.0

如果让设置永久生效呢?nvm alias default xx.xx.x

bash
nvm use 12.22.0
nvm alias default 12.22.0

执行这两条命令就可以了。

总结 ​

这样版本切换就非常的方便了。