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

nodejs -v

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 | sudo bash - 
sudo apt-get install nodejs

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

npm -v

nodejs -v

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...