Update node source
$ curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
Check which nodejs will be installed
$ apt-cache policy nodejs nodejs: Installed: (none) Candidate: 5.3.0-1nodesource1~trusty1 Version table: 5.3.0-1nodesource1~trusty1 0 500 https://deb.nodesource.com/node_5.x/ trusty/main amd64 Packages 0.10.25~dfsg2-2ubuntu1 0 500 http://us-west-1.ec2.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
Here candidate is 5.3.0-1nodesource1~trusty1 which is expected value.
Install node
This will install node and npm both.
$ sudo apt-get install nodejs dpkg -L nodejs | grep /bin/ /usr/lib/node_modules/npm/node_modules/semver/bin/semver /usr/lib/node_modules/npm/node_modules/which/bin/which /usr/lib/node_modules/npm/node_modules/mkdirp/bin/usage.txt /usr/lib/node_modules/npm/node_modules/mkdirp/bin/cmd.js /usr/lib/node_modules/npm/node_modules/nopt/bin/nopt.js /usr/lib/node_modules/npm/node_modules/request/node_modules/har-validator/bin/har-validator /usr/lib/node_modules/npm/node_modules/request/node_modules/node-uuid/bin/uuid /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js /usr/lib/node_modules/npm/bin/npm /usr/lib/node_modules/npm/bin/npm-cli.js /usr/lib/node_modules/npm/bin/npm.cmd /usr/lib/node_modules/npm/bin/node-gyp-bin /usr/lib/node_modules/npm/bin/node-gyp-bin/node-gyp.cmd /usr/lib/node_modules/npm/bin/node-gyp-bin/node-gyp /usr/lib/node_modules/npm/bin/read-package-json.js /usr/bin/nodejs /usr/bin/npm
Note that if you have older versions of legacy node packages installed (node-legacy, npm), it is better to remove them before installing latest nodejs from deb.nodesource.com.
Check the installation
$ dpkg -l nodejs Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-===================================-======================-======================-============================================================================ ii nodejs 5.3.0-1nodesource1~tru amd64 Node.js event-based server-side javascript engine $ node --version v5.3.0 $ npm --version 3.3.12
Self update npm
To self update npm to latest version as npm installed with node may not be latest.
$ sudo npm install -g npm