By default, there's not a way to upgrade the version of Node.js you've got from within Node.js itself. That said, there's a fantastic tool for the community called nvm that allows you to manage the versions of Node.js that you've got installed locally.

One awesome aspect of nvm is that it manages the versions of Node.js, it doesn’t just upgrade them. This means you can have the latest version of Node.js, the latest versions of all the LTS release lines, and any number of other versions you want to use or test as well.

In this short tutorial, we’ll go through installing node in our machines with nvm. Just follow along.

Get NVM Install Script

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

This command will clone NVM repository from Github to ~/.nvm

On successful installation, you should see an output like this

Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Now lets reopen our terminal and verify if nvm installed perfectly.

nvm --version

Installing Node and NPM

Now that nvm is installed, we can simply install node

nvm install node

After installation is complete, verify the install by

node -v

and

npm -v

Install other versions of Node

With nvm, we can install other versions of node as well and activate as per our requirements.

nvm install --lts
nvm install 12.14.0

To list installed node version

nvm ls

In my case, I’ve the following installed on my machine

        v12.7.0
       v12.10.0
       v12.14.0
->      v13.5.0
         system
default -> stable (-> v13.5.0)
node -> stable (-> v13.5.0) (default)
stable -> 13.5 (-> v13.5.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/erbium (-> v12.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.18.0 (-> N/A)
lts/erbium -> v12.14.0

current version is 13.5.0 but i can switch between other versions if i need to, likeso

nvm use 12.14.0

It will change your current version to 12.14.0

You can also learn how to install node from NodeSource

You may also Like