Ubuntu Server: How to Update Node.js to the Latest Version
If you're looking to upgrade to the latest stable version of NodeJS that's already installed on your Ubuntu Server, simply run the following commands in succession:
sudo npm cache clean -f sudo npm install -g n sudo n stable
Finally, link the command line to the latest version of NodeJS.
sudo apt-get install --reinstall nodejs-legacy
If the latest stable version of NodeJS isn't cutting it for you and you want to switch to the absolute latest version, simply replace sudo n stable with sudo n latest and enjoy!