nvm nodejs版本管理工具

2022-05-25 20:15:12 浏览数 (1)

可以很方便地切换 node 版本

安装

代码语言:javascript复制
#在线安装
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

#下载到本地再安装
cuiwei@weideMacBook-Pro nvm-master % sh install.sh 
=> Downloading nvm from git to '/Users/cuiwei/.nvm'
=> Cloning into '/Users/cuiwei/.nvm'...
remote: Enumerating objects: 345, done.
remote: Counting objects: 100% (345/345), done.
remote: Compressing objects: 100% (292/292), done.
remote: Total 345 (delta 38), reused 170 (delta 28), pack-reused 0
Receiving objects: 100% (345/345), 194.77 KiB | 280.00 KiB/s, done.
Resolving deltas: 100% (38/38), done.
* (HEAD detached at FETCH_HEAD)
  master
=> Compressing and cleaning up git repository

=> Profile not found. Tried ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile.
=> Create one of them and run this script again
   OR
=> Append the following lines to the correct file yourself:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

导入环境变量

代码语言:javascript复制
echo 'export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm' >>~/.zshrc

使生效

代码语言:javascript复制
source ~/.zshrc

常用命令

代码语言:javascript复制
nvm install stable ⬅️安装最新稳定版 node(当前最新稳定版11.6.0)
nvm install <version> ⬅️安装指定版本 (install v10.15.0或install 10.15.0)
nvm uninstall <version> ⬅️卸载指定版本node,(如果删除的为当前使用版本,要解绑,则执行 nvm deactivate)
nvm use <version> ⬅️切换使用指定的版本node
nvm current ⬅️显示当前使用的版本
nvm ls ⬅️列出所有安装的版本
nvm ls-remote ⬅️列出官网上node的所有版本
nvm alias <name> <version> ⬅️给不同的版本号添加别名
nvm unalias <name> ⬅️删除已定义的别名
nvm alias default <version> ⬅️指定默认版本(设定后需要打开新的终端才生效)
nvm deactivate ⬅️解除当前版本绑定

卸载

代码语言:javascript复制
Note:
  to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)
nvm

0 人点赞