I currently have node.js version 0.8.8, and npm 1.1.59 installed.
Whenever I run:
$ npm install -g express
I get this in return:
npm ERR! Error: EACCES, open '/Users/devinandrews/.npm/64a534c1-express.lock'
npm ERR! { [Error: EACCES, open '/Users/devinandrews/.npm/64a534c1-express.lock']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/Users/devinandrews/.npm/64a534c1-express.lock' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 12.1.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "express"
npm ERR! cwd /Users/devinandrews
npm ERR! node -v v0.8.8
npm ERR! npm -v 1.1.59
npm ERR! path /Users/devinandrews/.npm/64a534c1-express.lock
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, open '/Users/devinandrews/.npm/64a534c1-express.lock'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/devinandrews/npm-debug.log
npm ERR! not ok code 0
I'm pulling my hair out right now trying to figure this out.
Update:
I ran
$ npm -g ls
to see my what npm has installed globally:
/usr/local/lib
├─┬ express@3.0.0rc4
│ ├── commander@0.6.1
│ ├─┬ connect@2.4.4
│ │ ├── bytes@0.1.0
│ │ ├── formidable@1.0.11
│ │ ├── pause@0.0.1
│ │ └── qs@0.4.2
│ ├── cookie@0.0.4
│ ├── crc@0.2.0
│ ├── debug@0.7.0
│ ├── fresh@0.1.0
│ ├── methods@0.0.1
│ ├── mkdirp@0.3.3
│ ├── range-parser@0.0.4
│ └─┬ send@0.0.4
│ └── mime@1.2.6
└─┬ npm@1.1.59
├── abbrev@1.0.3
├── ansi@0.1.2
├── archy@0.0.2
├── block-stream@0.0.6
├── chownr@0.0.1
├── couch-login@0.1.10
├── fstream@0.1.18
├─┬ fstream-npm@0.1.1
│ └── fstream-ignore@0.0.5
├── glob@3.1.12
├── graceful-fs@1.1.10
├── inherits@1.0.0
├── ini@1.0.4
├─┬ init-package-json@0.0.5
│ └── promzard@0.2.0
├── lockfile@0.2.1
├── lru-cache@2.0.1
├── minimatch@0.2.6
├── mkdirp@0.3.4
├── node-gyp@0.6.7
├── nopt@2.0.0
├── npm-registry-client@0.2.6
├─┬ npmconf@0.0.11
│ └─┬ config-chain@1.1.1
│ └── proto-list@1.2.2
├── npmlog@0.0.2
├── once@1.1.1
├── osenv@0.0.3
├─┬ read@1.0.4
│ └── mute-stream@0.0.3
├── read-installed@0.0.2
├── read-package-json@0.1.4
├── request@2.9.203
├── retry@0.6.0
├── rimraf@2.0.2
├── semver@1.0.14
├── slide@1.1.3
├── tar@0.1.13
├── uid-number@0.0.3
└── which@1.0.5
but if i run:
$ npm ls
it returns empty?
I had the same problem, and npm cache clear
did not fix it. This problem is caused because the .npm
directory in your home directory was created with root privileges. Most likely the first npm command you ran was sudo npm -g
and now you are trying to npm install
in a local directory.
To solve:
sudo chown -R yourusername ~/.npm
rmdir ~/tmp
npm install
from package.json should work after this.
run npm cache clean
and try to install it again
i got the same problem , This problem is caused because the .npm directory in your home directory was created with root privileges.
use :
$sudo npm install -g express
The solution is:
1 - chown to your user the .npm folder :
sudo chown -R Webmaste /Users/webmaste/.npm/
2 - At your test folder or your folder:
sudo npm install -g express@2.5.8
3 - Invoke express from your actual location:
/usr/local/share/npm/bin/express
4 -
sudo cd . && npm install
5 - finally:
node app
the final message in the console should look like this:
Express server listening on port 3000 in development mode
Have you tried sudo npm -g install express?
If you can't see nothing wrong with using sudo npm install -g package_name
. And have the problem with typing a password you can always add yourself to sudoers files or to the same group that npm
executable belongs to.
And so to add yourself to sudoers for npm edit /etc/sudoers
adding something like this to the bottom of the file:
your_username localhost=/usr/local/bin/npm
Here is step by step guide on how to achieve that if you need more details.
In my case, instead of the ~/.npm directory being owned by root, it was ~/tmp, which I didn't think to check until one of the error messages finally led me to find. Procedure for fixing is pretty easy, since it's a tmp directory, we can just blow it away and start again with one owned by you.
sudo rmdir ~/tmp
mkdir ~/tmp