How to switch Node.js version using CLI?

You can easily switch the Node.js version when you have downloaded multiple different versions of Node.js.

You can see the available list of Node.js by running the command,

nvm ls

You will see output like,

->     v10.24.1
        v12.0.0
        v14.0.0
       v14.21.2
       v16.16.0
       v16.20.1
        v17.5.0
         system
default -> node (-> v17.5.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v17.5.0) (default)
stable -> 17.5 (-> v17.5.0) (default)
lts/* -> lts/hydrogen (-> 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
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.1
lts/hydrogen -> v18.17.0 (-> N/A)

In the response, You can see the first line indicates arrow with v10.24.1 is the selected version.

Now if you want to switch the version to v17.5.0, you can do it by running other commands,

nvm use <NODE_VERSION>

nvm use 17

Now you can check the result by nvm ls command,

       v10.24.1
        v12.0.0
        v14.0.0
       v14.21.2
       v16.16.0
       v16.20.1
->      v17.5.0
         system
default -> node (-> v17.5.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v17.5.0) (default)
stable -> 17.5 (-> v17.5.0) (default)
lts/* -> lts/hydrogen (-> 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
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.1
lts/hydrogen -> v18.17.0 (-> N/A)

Now You have successfully switched to v17.5.0 Node Version.