Upgrading NodeJS on Ubuntu using NPM

Last updated:

THIS POST IS OUTDATED. Look at Install NodeJS and NPM on Ubuntu 16.04 instead.

You've probably used apt-get to install NodeJS (if not, just run apt-get install nodejs-legacy) on your computer (mind the binary problems) so chances are that, when you actually get down to doing some work, you've fallen behind and need to update.

Weird as it sounds (think of it like using using gemto install a new ruby version), the best way to install and upgrade nodejs on Ubuntu is using npm. So here's what you need to do:

Upgrade npm

HEADS-UP sometimes you need to close your current terminal window and open a new one for changes to take effect

$ sudo npm cache clean -f
$ sudo npm install -g npm

View current npm version

$ npm -v

Upgrade nodejs

$ sudo npm install -g n
$ sudo n stable

View current nodejs version

$ node -v


Dialogue & Discussion