Oliver Nassar

Installing npm (node package manager) on Ubuntu 10.10

November 10, 2010

Okay, so the process has changed a bit as of late. Here are the updated steps, but feel free to read the whole post for more background on issues I ran into:

cd
sudo apt-get install -y libssl-dev
wget --no-check-certificate https://github.com/isaacs/npm/tarball/v0.2.15
mv v0.2.15 v0.2.15.tar.gz
gunzip v0.2.15.tar.gz
tar -xf v0.2.15.tar
cd isaacs-npm-*/
sudo chown -R $USER /usr/local
make
make install
cd ..
rm -r isaacs-npm-*
rm v0.2.15.tar

NOTE read this whole post first before running the code. I make some mark some important caveats at the end.

After installing node.js on my machine (see node.js: first impressions..), I wanted to install Socket.IO to play around with a cool use-case of node.js. This lead me to the requirement of installing npm and then using npm to install the socket.io package. Heres the walkthrough:

cd
sudo apt-get install -y libssl-dev
wget http://download.github.com/isaacs-npm-v0.2.7-3-0-g876e8bd.tar.gz
gunzip isaacs-npm-v0.2.7-3-0-g876e8bd.tar.gz
tar -xf isaacs-npm-v0.2.7-3-0-g876e8bd.tar
cd isaacs-npm-94d4012/
sudo make
sudo make install
cd ..
rm isaacs-npm-v0.2.7-3-0-g876e8bd.tar
rm -rf isaacs-npm-94d4012/

Worth noting is that I tried running make instead of sudo make but got the following error:

make: Warning: File 'Makefile' has modification time 1.4e+05 s in the future
node cli.js install npm
npm info it worked if it ends with ok
npm info using npm@0.2.7-3
npm info using node@v0.2.4
npm ERR! Error: EACCES, Permission denied '/usr/local/lib/node/.npm'
npm ERR!at node.js:772:9
npm ERR! There appear to be some permission problems
npm ERR! See the section on 'Permission Errors' at
npm ERR!http://github.com/isaacs/npm#readme
npm ERR! This will get better in the future, I promise.
npm not ok
make: *** [install] Error 13

Having not read the page http://github.com/isaacs/npm#readme, I simply ran sudo make and it seemed to install properly, but with the following warning/provision:

make: Warning: File 'Makefile' has modification time 1.4e+05 s in the future
node cli.js install npm
npm info it worked if it ends with ok
npm info using npm@0.2.7-3
npm info using node@v0.2.4
npm ERR! sudon't! 
npm ERR! sudon't! Running npm as root is not recommended!
npm ERR! sudon't! Seriously, don't do this!
npm ERR! sudon't!
npm info fetch http://registry.npmjs.org/npm/-/npm-0.2.7-3.tgz
npm info preinstall npm@0.2.7-3
npm info install npm@0.2.7-3
npm info postinstall npm@0.2.7-3
npm info preactivate npm@0.2.7-3
npm info activate npm@0.2.7-3
npm info postactivate npm@0.2.7-3
npm info build Success: npm@0.2.7-3
npm ok
make: warning:Clock skew detected.Your build may be incomplete.

I read the documentation afterwords, and saw this nugget:

If it dies with a "Permission Denied" or EACCESS error, then that probably
means that you are running node in a shared root-owned location. You've got
options.

Using sudo with npm is Very Not Recommended. Anyone can publish anything,
and package installations can run arbitrary scripts.

I don't really care right now since this is just on a local Ubuntu running through Parallels, but ideally I'll just follow the 3 various options in the readme linked to above (and here) for a live server.

Wait a second, there's another step that requires permissions, so eff it; just run the following to get by this issue:

sudo chown -R $USER /usr/local

Now to install Socket.IO, run the following:

npm install socket.io

If you don't do the above permission step, and try to run the npm install code, you'll get the following:

npm info it worked if it ends with ok
npm info using npm@0.2.7-3
npm info using node@v0.2.4
npm ERR! Error installing socket.io@0.6.1
npm ERR! Error: EACCES, Permission denied '/usr/local/lib/node/.npm/.cache/socket.io'
npm ERR!at node.js:772:9
npm ERR! There appear to be some permission problems
npm ERR! See the section on 'Permission Errors' at
npm ERR!http://github.com/isaacs/npm#readme
npm ERR! This will get better in the future, I promise.
npm not ok

So the easier solution (eg. not the sudo-ing I did above) is by issuing the chown command mentioned.

Anyway, there are the steps. Will follow up with a post about how to get it working in a real case.