Q:

Installing NodeJS contextify package yields an error

I am 1 hour into NodeJS, so bear with me. One of the packages my project requires is JSDom. After prodding much of the Internet I found that JSDOm has a dependency called contextify, which is somehow handled within the JSDom installation in itself. So this is what I Do:
sudo npm install jsdom 

and everything goes fine, until I get the following:
gyp WARN install got an error, rolling back install
gyp ERR! rebuild error Error: EACCES, stat '/root/.node-gyp/0.8.2'
gyp ERR! not ok
npm ERR! contextify@0.1.7 install: `node-gyp rebuild`
npm ERR! `sh "-c" "node-gyp rebuild"` failed with 1
npm ERR!
npm ERR! Failed at the contextify@0.1.7 install script.
npm ERR! This is most likely a problem with the contextify package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls contextify
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.2.0-60-generic
npm ERR! command "/opt/node/bin/node" "/opt/node/bin/npm" "install" "contextify"
npm ERR! cwd /opt/node
npm ERR! node -v v0.8.2
npm ERR! npm -v 1.1.36
npm ERR! code ELIFECYCLE
npm ERR! message contextify@0.1.7 install: `node-gyp rebuild`
npm ERR! message `sh "-c" "node-gyp rebuild"` failed with 1
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /opt/node/npm-debug.log
npm ERR! not ok code 0

STUMPED!!!
I found that for contextify to run on Ubuntu, I must have make, python and G++. I have them all. So what exactly am I missing out here? 
FYI, the commands preceding the JSDOM install attempt are:
mkdir ~/.node-gyp
chmod -R 777 ~/.node-gyp

I also, tried the following:
npm install -g node-gyp
npm install contextify

At the second command, I run into the same problem. 

A:

you might need to do 
sudo npm install -g npm 
and try again (it worked on my mac) 
or see this Error installing contextify- node-gyp rebuild failed
if you did a standard apt-get on node it could well be behind the times and taking the latest bundle release might fix it 

