47

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?

Devin
  • 737
  • 2
  • 8
  • 14
  • Are you running it as an administrator? Check the lock file in question to see if it isn't owned by some user different from the one you're running as — I cannot think of a reason it would be, but the errors indicate you don't have permissions to open that file, which should be owned by your user. – lanzz Sep 01 '12 at 22:17
  • i dont even see a .npm folder in my users/devinandrews directory. i could install it by going sudo npm install -g express, but it is advised that I do not do that. – Devin Sep 01 '12 at 22:25
  • Are you looking for that `.npm` folder in a shell or in Finder? You might have dot-names hidden in Finder (as it is the default); note that I'm assuming you're on OSX judging by your home directory location. – lanzz Sep 01 '12 at 22:27
  • I was looking in finder. (yes os x 10.8). I just ran this command open -a Finder /usr/local/bin and to my surprise I found an express file in there? (i have been trying to do this through all different kinds of googled methods all day, so ive put many commands in all day trying to get this to work) I just now put a fresh install of node and npm, and am trying to do this. (by this i mean am trying to install express) – Devin Sep 01 '12 at 22:31
  • it ends up telling me that /Users/devinandrews/.npm/64a534c1-express.lock does not exist. I'm guessing this is the problem? – Devin Sep 01 '12 at 22:39
  • What happens if you install it locally (without -g) ? – Hector Correa Sep 01 '12 at 23:26
  • Same error message if i try to cd into my project folder and run any of the following: $ npm install express, or $ npm install. Maybe i need this /35596296-express-3-0-0.lock file? (since it doesnt currently exist) – Devin Sep 02 '12 at 08:36
  • Please consider this [solution](http://stackoverflow.com/questions/16151018/npm-throws-error-without-sudo/24404451#24404451) instead of hacking system permissions – Anconia Nov 19 '14 at 16:32
  • I'm also facing the same issue. Can anyone tell me what's the produce to resolve this issue in windows(7-64bit) operating system? – Aditya May 16 '17 at 12:32
  • Have you tried sudo npm -g install express? – Michael Smith Sep 02 '12 at 13:15
  • I have, and that works, however i need it to install locally in my apps project folder in order to use it in my project. – Devin Sep 02 '12 at 15:56

9 Answers9

146

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
  • This may not be necessary but I also had to rmdir ~/tmp

npm install from package.json should work after this.

talles
  • 14,356
  • 8
  • 45
  • 58
ty.
  • 10,924
  • 9
  • 52
  • 71
  • 1
    I'm running OSX. What would be my username for chown? .npm is currently installed in my Users/[my name here] folder. ;; also sorry for getting back almost 2 months later, haha. – Devin Jan 30 '13 at 21:00
  • Ah it was because the dot notation is no longer used. and I used $USER as I had no idea what my username was supposed to be.. Either way, thank you! – Devin Jan 31 '13 at 14:29
  • is it a problem to run `sudo npm install -g express`? – Connor Leech Nov 26 '13 at 12:59
  • 3
    @ConnorLeech no, but someday you're going to just want to `npm install` without sudo. I'd guess that's where most of the traffic to this post comes from. – ty. Nov 27 '13 at 19:51
  • anyone know the windows equivalent for this issue? – Rachael Mar 25 '14 at 22:42
  • 2
    This did not work for me. Running `ls -la` in the home (`~`) directory already shows my Mac OS X username as the owner of my `.npm` file. – 2540625 Aug 12 '14 at 07:00
6

run npm cache clean and try to install it again

supernova
  • 3,814
  • 3
  • 22
  • 37
6

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
user1640025
  • 77
  • 1
  • 1
0

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
explunit
  • 18,967
  • 6
  • 69
  • 94
galo hernandez
  • 163
  • 1
  • 3
  • First off, thank you. Secondly, If it makes a difference, I'm in OSX. & not too familiar with chown. What is the username I should be using when running chown? – Devin Jan 30 '13 at 20:59
  • `sudo cd` makes no sense at all. cd is a built-in so even if sudo could launch it, it would be in a sub-shell – Janus Troelsen May 19 '16 at 10:23
0

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.

Alejandro Silva
  • 8,808
  • 1
  • 35
  • 29
Mark Karwowski
  • 619
  • 6
  • 7
0

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
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Doc Honcho
  • 11
  • 2
0

Run powershell as administrator, then type:

Set-ExecutionPolicy RemoteSigned

then try install again.

Veljko P.
  • 89
  • 5
0

As a side note, if you other solutions haven't helped, I have had the same issue and realised what was wrong -- which maybe of interest here.

I had nodemon running on another project -- when I installed locally express. Check you're not running express on another project and trying to install express on a new project. Just a heads up and hope it helps. By the way, just copied the dependency from the package file, and pasted into my new project and ran npm install and checked, express got installed.

Muniro
  • 1,989
  • 3
  • 11
  • 9
0

Go C:\Users\User_Name\AppData\Roaming\npm-cache_logs and delete all files

Then run again:

npm install

Or you reinstall Nodejs and tick Chocolatey

You can install an older version of Nodejs to be compatible with the version of the component you are building https://nodejs.org/en/download/releases/

Trinh Hieu
  • 379
  • 3
  • 6