执行 下载安装命令

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
sunyuhua@sunyuhua-HKF-WXX:~$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15037  100 15037    0     0  23422      0 --:--:-- --:--:-- --:--:-- 23458
=> Downloading nvm from git to '/home/sunyuhua/.nvm'
=> 正克隆到 '/home/sunyuhua/.nvm'...
remote: Enumerating objects: 362, done.
remote: Counting objects: 100% (362/362), done.
remote: Compressing objects: 100% (311/311), done.
remote: Total 362 (delta 43), reused 159 (delta 25), pack-reused 0
接收对象中: 100% (362/362), 186.76 KiB | 394.00 KiB/s, 完成.
处理 delta 中: 100% (43/43), 完成.
* (头指针在 FETCH_HEAD 分离)
  master
=> Compressing and cleaning up git repository

=> Appending nvm source string to /home/sunyuhua/.bashrc
=> Appending bash_completion source string to /home/sunyuhua/.bashrc
=> 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
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

执行source 命令

source ~/.bashrc

检查是不是安装成功

nvm -v

nvm 的常用命令

nvm常用命令

nvm ls-remote  查看 Node 远程版本库
nvm install node  将安装最新版本的 Node
nvm install v12.7.0  将安装 12.7.0 版本的 Node
nvm uninstall v12.7.0  卸载 12.7.0 版本的 Node
nvm ls  查看已经安装的 Node 版本
nvm use v12.7.0 切换 12.7.0 为当前使用的版本
nvm alias default v12.7.0 将 12.7.0 设置为 Node 的默认版本
nvm which v12.7.0 查看 12.7.0 版本的 Node 的安装目录,比如:/Users/ccp/.nvm/versions/node/v12.7.0/bin/node
nvm --help  查看更多命令用法

其他相关命令

command -v nvm  查看 nvm 是否安装成功
node -v 查看当前使用的 Node 版本
which node  查看当前 Node 的安装目录