Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm will not install express?

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 ├─┬ [email protected] │ ├── [email protected] │ ├─┬ [email protected] │ │ ├── [email protected] │ │ ├── [email protected] │ │ ├── [email protected] │ │ └── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ ├── [email protected] │ └─┬ [email protected] │   └── [email protected] └─┬ [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├─┬ [email protected]   │ └── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├─┬ [email protected]   │ └── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├─┬ [email protected]   │ └─┬ [email protected]   │   └── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├─┬ [email protected]   │ └── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   ├── [email protected]   └── [email protected] 

but if i run:

$ npm ls 

it returns empty?

like image 430
Devin Avatar asked Sep 01 '12 22:09

Devin


People also ask

Why npm install is not working?

If your npm is broken: On Mac or Linux, reinstall npm. Windows: If you're on Windows and you have a broken installation, the easiest thing to do is to reinstall node from the official installer (see this note about installing the latest stable version).


1 Answers

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.

like image 126
ty. Avatar answered Sep 23 '22 04:09

ty.