Setting the Default Node.JS version with nvm

Johnny Simpson - Oct 12 '22 - - Dev Community

When developing projects and products in Node.JS, it becomes essential to set the Node.JS version being used on your computer. nvm is a really useful tool for changing your Node.JS version on the fly. If you need to install nvm, you can learn how to do that here.

nvm also lets you set the default version of Node.JS so that you don't have to constantly change it. To do that, you can use the nvm command like so:

nvm alias default 18.10.0
Enter fullscreen mode Exit fullscreen mode

Before you do that, though, make sure you have the version you want to use installed. You can do that using nvm install:

nvm install 18.10.0
Enter fullscreen mode Exit fullscreen mode

If you want to see what versions are available for you to set as your default version of Node.JS, try using nvm ls, which will return a list likethe one below. It also states which version is set as the default, beside the default -> node line.

❯ nvm ls
       v14.15.1
        v16.4.0
       v16.13.2
       v16.14.0
->      v18.3.0
         system
default -> node (-> v18.3.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v18.3.0) (default)
stable -> 18.3 (-> v18.3.0) (default)
lts/* -> lts/gallium (-> 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.20.0 (-> N/A)
lts/gallium -> v16.17.0 (-> N/A)
Enter fullscreen mode Exit fullscreen mode

Also, running node -v will show you which version you are currently using. If it's not the one you want, you can set it back to the default using nvm use default:

❯ node -v
v16.18.0
❯ nvm use default
Now using node v18.3.0 (npm v8.11.0)
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .