Install (macOS)
Open the Terminal and run
1
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
This will download the NVM install script and install it on your computer
Create a configuration file for the Zsh shell if you do not have one
1
touch ~/.zshrc
Append the following code to the
.zshrc
file1
2export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvmExecute the configuration file to take effect
1
source ~/.zshrc
Usage
Check nvm version
1 | nvm -v |
List node version available to install
1 | nvm ls-remote |
Sample Output
1
2
3
4
5
6
7
8
9 v0.1.14
v0.1.15
v0.1.16
...
v20.14.0 (Latest LTS: Iron)
v21.0.0
...
v22.1.0
v22.2.0
Install a specific version of the node
1 | # v20.14.0 |
Validate installation
1 | node -v |
Sample Output
1
2
3
4
5 v20.14.0
10.7.0
v14.21.3
6.14.18
Show installed node executable path
1 | # Installed executable path for v20 |
Sample Output
1
2 /Users/andy/.nvm/versions/node/v20.14.0/bin/node
/Users/andy/.nvm/versions/node/v14.21.3/bin/node
List node version installed
1 | nvm ls |
Sample Output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 v14.21.3
-> v20.14.0
default -> v14.21.3
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v20.14.0) (default)
stable -> 20.14 (-> v20.14.0) (default)
lts/* -> lts/iron (-> v20.14.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
lts/gallium -> v16.20.2 (-> N/A)
lts/hydrogen -> v18.20.3 (-> N/A)
lts/iron -> v20.14.0
Switch node version
1 | # Use node v14 |
Sample Output
1
2 Now using node v14.21.3 (npm v6.14.18)
Now using node v20.14.0 (npm v10.7.0)
Reference
About this Post
This post is written by Andy, licensed under CC BY-NC 4.0.