Ubuntu Server: How to Update Node.js to the Latest Version
If you want to upgrade to the latest stable version of NodeJS already installed on your Ubuntu Server, you should successively run the following commands:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Then rebind the command line to the latest version of NodeJS
sudo apt-get install --reinstall nodejs-legacy
If you are not satisfied with the latest stable version and you want the latest version of the NodeJS, just replace sudo n stable
with sudo n latest
and enjoy