How to update NVM

Many JavaScript developers prefer to use NVM instead of a regular NodeJS installation because NVM provides them with a way to install multiple NodeJS and npm versions on one computer.

This is very helpful since NodeJS is a rapidly evolving software and many of its versions receive a short support lifespan.

When you need to update your NVM version, you can use the following command in the Terminal for Linux and Mac OS:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

The command above will install NVM version 0.38.0 to your computer. If you already have a previous NVM version, it will overwrite the files and let you use the new one in its place. When a new NVM version is released, you need to replace the v0.38.0 URL segment with the new one.

For Windows, you need to run the NVM installer from its GitHub releases page

Once you updated your NVM version, you may also want to use the latest stable NodeJS and npm versions.

Updating NodeJS and npm versions

Usually, you can install the latest stable version of both NodeJS and npm with the following Terminal command:

nvm install node

Once the installation is finished, you may still found that your NVM uses the previous NodeJS version when you open a new window. For example, I have NodeJS versions v10.19.0 and v14.15.3 on my computer, and each time I opened a Terminal window, I always use v10.19.0.

Upon further inspection using nvm list command, I noticed the default version uses v10.19.0 as follows:

$ nvm list
->     v10.19.0
       v14.15.3
default -> v10.19.0
node -> stable (-> v14.15.3) (default)
stable -> 14.15 (-> v14.15.3) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/fermium (-> v14.15.3)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.23.0 (-> N/A)
lts/erbium -> v12.20.0 (-> N/A)
lts/fermium -> v14.15.3

When you install the latest stable version, you might need to change the default NodeJS version used by NVM with the alias command:

nvm alias default <version>

You can use replace the <version> tag with node to use the latest version too. Because my latest version is v14.15.3, I can use it to replace the <version> tag:

nvm alias default node
# or
nvm alias default v14.15.3

And that’s how you can update NVM, NodeJS, and npm installed on your computer. NVM is really neat because it allows you to use multiple NodeJS versions without having to install and remove them one by one.

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.