How to install Node 4.5 LTS on Ubuntu 14.04 Trusty Tahr


NB: on a separate occassion (on another 14.04 system) I failed to install Node 4 in the way described in this post and instead succeeded with the method described here.

The following worked for me in August 2016:

 curl -sL | sudo -E bash -
 sudo apt-get install -y nodejs

… subsequently to the installation above I get:

$ nodejs -v
$ node -v
… with no need to setup alternatives as I had to do in the installation method described in this post.

NB: the above process failed the first time it was adapted (I suspect due to some network vagary)

NB 2: The above also installs npm so subsequently to the above I configured npm to install global packages in my home directory as also described in this post:

$ which npm
$ npm --version
$ which npm
$ npm --version
$ npm config list
; cli configs
user-agent = "npm/2.15.9 node/v4.5.0 linux x64"

; node bin location = /usr/bin/nodejs
; cwd = /home/mperdikeas
; HOME = /home/mperdikeas
; 'npm config ls -l' to show all defaults.
$ npm config get prefix
$ cd && mkdir .node_modules_global
$ npm config set prefix=$HOME/.node_modules_global
$ npm config get prefix
$ cat .npmrc 
$ npm install npm --global
/home/mperdikeas/.node_modules_global/bin/npm -> /home/mperdikeas/.node_modules_global/lib/node_modules/npm/bin/npm-cli.js
npm@3.10.6 /home/mperdikeas/.node_modules_global/lib/node_modules/npm
… the above process also re-installed an updated version of npm in ~/.node_modules_global so we also need to update the PATH to ensure that npm is picked-up from that location:
$ cat ~/.bashrc_thisnode 
export PATH=~/.node_modules_global/bin:$PATH
… and ensure it works:
$ which npm
$ npm -version
Concluding, as part of the above post-node installation configuration we've accomplished three things:
  1. we've configured npm to install global packages in the home folder and not in /usr
  2. we've upgraded our version of npm (3.10.6 from 2.15.9) which also now runs from the home folder