Use NodeSource PPA. For details look at .
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -sudo apt-get install -y nodejs
Alternatively, for Node.js v5:
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -sudo apt-get install -y nodejs
P.S.: curl
package must be installed on server for these code lines.
Upgrading
If you have nodejs
already installed and want to update, then first remove current instalation and install it again using scripts above.
sudo apt-get remove --purge nodejs npm