Following Upgrading Node.js to latest version
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/node
For Upgrading Node.js to latest version
sudo n latest
If you need to do Undo then follow command
sudo apt-get install --reinstall nodejs-legacy # fix /usr/bin/node
sudo n rm 6.0.0 # replace number with version of Node that was installed
sudo npm uninstall -g n
This method of upgrading node is now unstable and should not be used. The best way to manage Node.js versions is to use NVM: Node Version Management.!
Installation
You can read the installation steps on the nvm [GitHub page][1]. There are only two easy steps for installation and configuration.
Using nvm
If you work with a lot of different Node.js utilities, you know that sometimes you need to quickly switch to other versions of Node.js without hosing your entire machine. That's where you can use nvm to download, install, and use different versions of Node.js:
nvm install 4.0
At any given time you can switch to another with use:
nvm use 0.12