How to install Node 4.5 LTS on Ubuntu 14.04 Trusty Tahr

source

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 https://deb.nodesource.com/setup_4.x | sudo -E bash -
 sudo apt-get install -y nodejs
   

… subsequently to the installation above I get:

$ nodejs -v
v4.5.0
mperdikeas@beorn:~#
$ node -v
v4.5.0
… 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
/usr/bin/npm
$ npm --version
2.15.9
$ which npm
/usr/bin/npm
$ npm --version
2.15.9
$ 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
/usr
$ cd && mkdir .node_modules_global
$ npm config set prefix=$HOME/.node_modules_global
$ npm config get prefix
/home/mperdikeas/.node_modules_global
$ cat .npmrc 
prefix=/home/mperdikeas/.node_modules_global
$ 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
/home/mperdikeas/.node_modules_global/bin/npm
$ npm -version
3.10.6
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