一、下载nvm
https://github.com/nvm-sh/nvm/releases/tag/v0.40.1
二、安装nvm
解压后
./install.sh
nvm -v
0.40.1
安装后,验证一下版本,搞定!
接下来开始安装node.js
三、安装node.js
1、查看一下有哪些版本可以安装,执行命令:nvm ls-remote
nvm ls-remote v0.1.14v0.1.15-----------------v10.12.0v10.13.0 (LTS: Dubnium)v10.14.0 (LTS: Dubnium)v10.14.1 (LTS: Dubnium)v10.14.2 (LTS: Dubnium)v10.15.0 (LTS: Dubnium)v10.15.1 (LTS: Dubnium)v10.15.2 (LTS: Dubnium)v10.15.3 (LTS: Dubnium)v10.16.0 (LTS: Dubnium)v10.16.1 (LTS: Dubnium)v10.16.2 (LTS: Dubnium)v10.16.3 (LTS: Dubnium)v10.17.0 (LTS: Dubnium)v10.18.0 (LTS: Dubnium)v10.18.1 (LTS: Dubnium)v10.19.0 (LTS: Dubnium)v10.20.0 (LTS: Dubnium)v10.20.1 (LTS: Dubnium)v10.21.0 (LTS: Dubnium)v10.22.0 (LTS: Dubnium)v10.22.1 (LTS: Dubnium)v10.23.0 (LTS: Dubnium)v10.23.1 (LTS: Dubnium)v10.23.2 (LTS: Dubnium)v10.23.3 (LTS: Dubnium)v10.24.0 (LTS: Dubnium)v10.24.1 (Latest LTS: Dubnium)v11.0.0v11.1.0v11.2.0v11.3.0v11.4.0v11.5.0v11.6.0v11.7.0v11.8.0v11.9.0v11.10.0v11.10.1v11.11.0v11.12.0v11.13.0v11.14.0v11.15.0v12.0.0v12.1.0v12.2.0v12.3.0v12.3.1v12.4.0v12.5.0v12.6.0v12.7.0v12.8.0v12.8.1v12.9.0v12.9.1v12.10.0v12.11.0v12.11.1v12.12.0v12.13.0 (LTS: Erbium)v12.13.1 (LTS: Erbium)v12.14.0 (LTS: Erbium)v12.14.1 (LTS: Erbium)v12.15.0 (LTS: Erbium)v12.16.0 (LTS: Erbium)v12.16.1 (LTS: Erbium)v12.16.2 (LTS: Erbium)v12.16.3 (LTS: Erbium)v12.17.0 (LTS: Erbium)v12.18.0 (LTS: Erbium)v12.18.1 (LTS: Erbium)v12.18.2 (LTS: Erbium)v12.18.3 (LTS: Erbium)v12.18.4 (LTS: Erbium)v12.19.0 (LTS: Erbium)v12.19.1 (LTS: Erbium)v12.20.0 (LTS: Erbium)v12.20.1 (LTS: Erbium)v12.20.2 (LTS: Erbium)v12.21.0 (LTS: Erbium)v12.22.0 (LTS: Erbium)v12.22.1 (LTS: Erbium)v12.22.2 (LTS: Erbium)v12.22.3 (LTS: Erbium)v12.22.4 (LTS: Erbium)v12.22.5 (LTS: Erbium)v12.22.6 (LTS: Erbium)v12.22.7 (LTS: Erbium)v12.22.8 (LTS: Erbium)v12.22.9 (LTS: Erbium)v12.22.10 (LTS: Erbium)v12.22.11 (LTS: Erbium)v12.22.12 (Latest LTS: Erbium)v13.0.0v13.0.1v13.1.0v13.2.0v13.3.0v13.4.0v13.5.0v13.6.0v13.7.0v13.8.0v13.9.0v13.10.0v13.10.1v13.11.0v13.12.0v13.13.0v13.14.0v14.0.0v14.1.0v14.2.0v14.3.0v14.4.0v14.5.0v14.6.0v14.7.0v14.8.0v14.9.0v14.10.0v14.10.1v14.11.0v14.12.0v14.13.0v14.13.1v14.14.0v14.15.0 (LTS: Fermium)v14.15.1 (LTS: Fermium)v14.15.2 (LTS: Fermium)v14.15.3 (LTS: Fermium)v14.15.4 (LTS: Fermium)v14.15.5 (LTS: Fermium)v14.16.0 (LTS: Fermium)v14.16.1 (LTS: Fermium)v14.17.0 (LTS: Fermium)v14.17.1 (LTS: Fermium)v14.17.2 (LTS: Fermium)v14.17.3 (LTS: Fermium)v14.17.4 (LTS: Fermium)v14.17.5 (LTS: Fermium)v14.17.6 (LTS: Fermium)v14.18.0 (LTS: Fermium)v14.18.1 (LTS: Fermium)v14.18.2 (LTS: Fermium)v14.18.3 (LTS: Fermium)v14.19.0 (LTS: Fermium)v14.19.1 (LTS: Fermium)v14.19.2 (LTS: Fermium)v14.19.3 (LTS: Fermium)v14.20.0 (LTS: Fermium)v14.20.1 (LTS: Fermium)v14.21.0 (LTS: Fermium)v14.21.1 (LTS: Fermium)v14.21.2 (LTS: Fermium)v14.21.3 (Latest LTS: Fermium)v15.0.0v15.0.1v15.1.0v15.2.0v15.2.1v15.3.0v15.4.0v15.5.0v15.5.1v15.6.0v15.7.0v15.8.0v15.9.0v15.10.0v15.11.0v15.12.0v15.13.0v15.14.0v16.0.0v16.1.0v16.2.0v16.3.0v16.4.0v16.4.1v16.4.2v16.5.0v16.6.0v16.6.1v16.6.2v16.7.0v16.8.0v16.9.0v16.9.1v16.10.0v16.11.0v16.11.1v16.12.0v16.13.0 (LTS: Gallium)v16.13.1 (LTS: Gallium)v16.13.2 (LTS: Gallium)v16.14.0 (LTS: Gallium)v16.14.1 (LTS: Gallium)v16.14.2 (LTS: Gallium)v16.15.0 (LTS: Gallium)v16.15.1 (LTS: Gallium)v16.16.0 (LTS: Gallium)v16.17.0 (LTS: Gallium)v16.17.1 (LTS: Gallium)v16.18.0 (LTS: Gallium)v16.18.1 (LTS: Gallium)v16.19.0 (LTS: Gallium)v16.19.1 (LTS: Gallium)v16.20.0 (LTS: Gallium)v16.20.1 (LTS: Gallium)v16.20.2 (Latest LTS: Gallium)v17.0.0v17.0.1v17.1.0v17.2.0v17.3.0v17.3.1v17.4.0v17.5.0v17.6.0v17.7.0v17.7.1v17.7.2v17.8.0v17.9.0v17.9.1v18.0.0v18.1.0v18.2.0v18.3.0v18.4.0v18.5.0v18.6.0v18.7.0v18.8.0v18.9.0v18.9.1v18.10.0v18.11.0v18.12.0 (LTS: Hydrogen)v18.12.1 (LTS: Hydrogen)v18.13.0 (LTS: Hydrogen)v18.14.0 (LTS: Hydrogen)v18.14.1 (LTS: Hydrogen)v18.14.2 (LTS: Hydrogen)v18.15.0 (LTS: Hydrogen)v18.16.0 (LTS: Hydrogen)v18.16.1 (LTS: Hydrogen)v18.17.0 (LTS: Hydrogen)v18.17.1 (LTS: Hydrogen)v18.18.0 (LTS: Hydrogen)v18.18.1 (LTS: Hydrogen)v18.18.2 (LTS: Hydrogen)v18.19.0 (LTS: Hydrogen)v18.19.1 (LTS: Hydrogen)v18.20.0 (LTS: Hydrogen)v18.20.1 (LTS: Hydrogen)v18.20.2 (LTS: Hydrogen)v18.20.3 (LTS: Hydrogen)v18.20.4 (LTS: Hydrogen)v18.20.5 (Latest LTS: Hydrogen)v19.0.0v19.0.1v19.1.0v19.2.0v19.3.0v19.4.0v19.5.0v19.6.0v19.6.1v19.7.0v19.8.0v19.8.1v19.9.0v20.0.0v20.1.0v20.2.0v20.3.0v20.3.1v20.4.0v20.5.0v20.5.1v20.6.0v20.6.1v20.7.0v20.8.0v20.8.1v20.9.0 (LTS: Iron)v20.10.0 (LTS: Iron)v20.11.0 (LTS: Iron)v20.11.1 (LTS: Iron)v20.12.0 (LTS: Iron)v20.12.1 (LTS: Iron)v20.12.2 (LTS: Iron)v20.13.0 (LTS: Iron)v20.13.1 (LTS: Iron)v20.14.0 (LTS: Iron)v20.15.0 (LTS: Iron)v20.15.1 (LTS: Iron)v20.16.0 (LTS: Iron)v20.17.0 (LTS: Iron)v20.18.0 (LTS: Iron)v20.18.1 (Latest LTS: Iron)v21.0.0v21.1.0v21.2.0v21.3.0v21.4.0v21.5.0v21.6.0v21.6.1v21.6.2v21.7.0v21.7.1v21.7.2v21.7.3v22.0.0v22.1.0v22.2.0v22.3.0v22.4.0v22.4.1v22.5.0v22.5.1v22.6.0v22.7.0v22.8.0v22.9.0v22.10.0v22.11.0 (LTS: Jod)v22.12.0 (Latest LTS: Jod)v23.0.0v23.1.0v23.2.0v23.3.0v23.4.0v23.5.0
2、安装node.js
(1)安装最新版本
#安装最新版本,执行nvm install node命令nvm install nodeDownloading and installing node v23.5.0...
Downloading https://nodejs.org/dist/v23.5.0/node-v23.5.0-darwin-x64.tar.xz...
######################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v23.5.0 (npm v10.9.2)
Creating default alias: default -> node (-> v23.5.0)#查看当前安装了什么版本,执行nvm list命令
apple@xqdd nvm-0.40.1 % nvm list
-> v23.5.0
default -> node (-> v23.5.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v23.5.0) (default)
stable -> 23.5 (-> v23.5.0) (default)
lts/* -> lts/jod (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2 (-> N/A)
lts/hydrogen -> v18.20.5 (-> N/A)
lts/iron -> v20.18.1 (-> N/A)
lts/jod -> v22.12.0 (-> N/A)
(2)指定版本安装
#指定安装22版本nvm install 22
Downloading and installing node v22.12.0...
Downloading https://nodejs.org/dist/v22.12.0/node-v22.12.0-darwin-x64.tar.xz...
######################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v22.12.0 (npm v10.9.0)#查看已安装版本
apple@xqdd nvm-0.40.1 % nvm list
-> v22.12.0v23.5.0
default -> node (-> v23.5.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v23.5.0) (default)
stable -> 23.5 (-> v23.5.0) (default)
lts/* -> lts/jod (-> v22.12.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2 (-> N/A)
lts/hydrogen -> v18.20.5 (-> N/A)
lts/iron -> v20.18.1 (-> N/A)
#新安装的
lts/jod -> v22.12.0