You can go even without removing old node, just by adding 6.x repository and updating.
If you want to remove it you can do it by executing
- sudo apt-get remove nodejs
This is fully optional step, as you can get it working without removing.
Basically, we will install it using PPA method.
Download repo installer by executing:
- curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
After it downloads, you can inspect it if you want with any text editor:
If it’s OK, run it:
- sudo bash nodesource_setup.sh
Let it finish.
Now you are ready to install latest Node.js. If you didn’t removed Node.js, just run:
root@node-512mb-nyc1-01:~# sudo apt-get -y upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
Use 'sudo apt autoremove' to remove it.
The following packages will be upgraded:
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 10.1 MB of archives.
After this operation, 37.5 MB of additional disk space will be used.
As you can see, it will upgrade your Node.js to latest. Yet, if you removed it in first step, install it with:
- sudo apt-get -y install nodejs
That is it! You can now verify version of Node.js with:
At time of writing this it should output:
You can also verify
npm version with:
At time of writing it is: