NVM
Installing and Updating
1 2 3
| curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
|
在bash_profile和zshrc添加如下语句。source更新。(用那个就添加那个,我两个都添加了)
1 2 3
| export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
|
输入 nvm 检查能否正常
1 2 3
| $ nvm --> Node Version Manager (v0.35.3) (....略)
|
Usage
查看当前ndoe
1 2 3 4 5 6
| $ nvm ls --> v12.14.1 system default -> 12.14.1 (-> v12.14.1) node -> stable (-> v12.14.1) (default) stable -> 12.14 (-> v12.14.1) (default)
|
可以看到目前系统使用的node是12.14.1
使用 “nvm install ” 安装指定版本的 node
1 2 3 4 5 6 7 8 9
| $ nvm install v11.10.0
$ nvm ls v11.10.1 -> v12.14.1 system default -> 12.14.1 (-> v12.14.1) node -> stable (-> v12.14.1) (default) stable -> 12.14 (-> v12.14.1) (default)
|
现在已经有两个版本的 node 了,使用 “nvm use ” 可以切换 node 版本