This setup of instructions will work on Ubuntu, To install nodejs and npm on Centos checkout here...

Before installing nodejs, check if you have any previous version.

node -v
Command 'node' not found, but can be installed with:

Above error means, nodejs is not installed.  If you have nodejs installed, you can remove it using following command.

sudo apt remove nodejs

Install Nodejs Using NPM

NPM is node package manager.

sudo apt install npm
npm -v or npm –version

npm -v
3.5.2

nodejs -v
v8.10.0

Above will install both nodejs and npm. Note - we didn't get the latest version of npm and nodejs. To install the latest version follow the installations steps below.

Install Nodejs Latest From Repository

Nodejs and NPM can both be installed directly from the repository also.

Run following commands.

sudo apt-get updatesudo apt-get upgrade
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash - 
sudo apt-get install nodejs

Let us check the version numbers of nodjs and npm now...

npm -v
6.14.7

nodejs -v
v14.8.0

There you go, latest version of nodejs and npm are now installed on Ubuntu.

To keep track of latest releases, check out the following link...

https://github.com/nodesource/distributions