ubuntu 22.04安装nvm

本文介绍了如何使用NVM进行Node.js版本的安装和管理,包括通过执行安装脚本、设置环境变量、切换和设定默认版本等步骤。用户可以通过nvm命令安装特定版本,如nvminstall12.18.1,并可以使用nvmaliasdefault12.22.0来设置永久默认版本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

执行安装脚本

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

环境变量生效

source ~/.bashrc   

检验是否安装成功

nvm -v

使用说明

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`)

示例

比如:我要使用12.18.1

nvm install 12.18.1

比如:我要使用16.15.0

nvm install node -v                                                                                                                                        [12:34:07]
v12.18.1

现在想换回12.18.1

nvm use 12.18.1

查看当前所使用的版本:

node -v 
v12.18.1

永久默认

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

nvm use 12.22.0

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

nvm use 12.22.0
nvm alias default 12.22.0

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

总结

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值