I am Hack Sparrow
Captain of the Internets.

Two common Nodejs NPM Permission Denied errors on Linux

When trying to install npm itself

Permission Denied: '../lib/node_modules/npm/bin/npm-cli.js'

You are likely to encounter this error when you try to install npm. Even chmodding '/lib/node_modules' recursively won't fix the problem. You get this error and npm just fails to install:

$ curl http://npmjs.org/install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
101 7184 101 7184 0 0 56364 0 --:--:-- --:--:-- --:--:-- 118k
tar=/bin/tar
version:
tar (GNU tar) 1.22
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.
fetching: http://registry.npmjs.org/npm/-/npm-1.0.105.tgz
0.6.1
1.0.105
cleanup prefix=/usr/local

All clean!
npm ERR! error installing npm@1.0.105 Error: EACCES, permission denied '../lib/node_modules/npm/bin/npm-cli.js'
npm ERR! error rolling back npm@1.0.105 Error: UNKNOWN, unknown error '/usr/local/lib/node_modules/npm/node_modules'
npm ERR! Error: EACCES, permission denied '../lib/node_modules/npm/bin/npm-cli.js'
npm ERR! Report this *entire* log at:
npm ERR!
npm ERR! or email it to:
npm ERR!
npm ERR!
npm ERR! System Linux 2.6.32-318-ec2
npm ERR! command "/usr/local/bin/node" "/tmp/npm.9052/package/cli.js" "install" "-gf"
npm ERR! cwd /tmp/npm.9052/package
npm ERR! node -v v0.6.1
npm ERR! npm -v 1.0.105
npm ERR! path ../lib/node_modules/npm/bin/npm-cli.js
npm ERR! code EACCES
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /tmp/npm.9052/package/npm-debug.log
npm not ok
It failed

Caused by a tricky permission problem. To fix it, run sh using sudo:

$ curl http://npmjs.org/install.sh | sudo sh

When trying to install a Node package globally

For example when you try to install Express using the -g option, you get this error: Permission Denied: '../lib/node_modules/express/bin/express'.

$ npm install express -g
npm ERR! error installing express@2.5.0 Error: EACCES, permission denied '../lib/node_modules/express/bin/express'
npm ERR! Error: EACCES, permission denied '../lib/node_modules/express/bin/express'
npm ERR! Report this *entire* log at:
npm ERR!
npm ERR! or email it to:
npm ERR!
npm ERR!
npm ERR! System Linux 2.6.32-318-ec2
npm ERR! command "node" "/usr/local/bin/npm" "install" "express" "-g"
npm ERR! cwd /home/ubuntu
npm ERR! node -v v0.6.1
npm ERR! npm -v 1.0.105
npm ERR! path ../lib/node_modules/express/bin/express
npm ERR! code EACCES
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/ubuntu/npm-debug.log
npm not ok

Again caused by the same tricky permission problem. Fix it by running npm using sudo.

$ sudo npm install express -g

So now you know, anytime npm throws a "Error: EACCES, permission denied" at you, just sudo the sucker. Don't forget to share the tip with your friends.

One Response to “Two common Nodejs NPM Permission Denied errors on Linux”

  1. angel says:

    or install node & npm without root permissions:

    http://increaseyourgeek.wordpress.com/2010/08/18/install-node-js-without-using-sudo/

Make a Comment