Points to Remember
If you are installing node for the first time then, use the
NodeSource PPA and first choose the version of node you want to install.
Following are the sources for the node versions
for Node.js v4
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
for Node.js v5
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
for Node.js v6
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
for Node.js v7
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
Once this is done, then update your repositories by command
sudo apt-get update
Now, finally install NodeJs and Npm using the following command
sudo apt-get install nodejs sudo apt-get install npm
To check the version of node, try command
node -v and npm version by command
Upgrading NodeJs and Npm
If you already have node and npm install and you want to upgrade the version then you should first run the following command to remove them.
sudo apt-get purge nodejs npm
This will remove nodejs and npm, now you can follow the steps mentioned above to install fresh copy of node and npm.