error when install npm

npm install npm@latest -g

nodejs version : v10.16.1
old npm install : 6.9.0

Unhandled rejection Error: EACCES: permission denied, mkdir '/Users/admin/.npm/_cacache/index-v5/af/03'

npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://npm.community>

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/admin/.npm/_logs/2019-08-01T03_43_06_967Z-debug.log

There were some problems where a past use of sudo with an npm install would leave behind a file with the wrong ownership. The quick fix is run this to fix the ownership, then try your install again:

sudo chown -R $USER ~/.npm

The most common problem was fixed in npm 6.10.2: Release: 6.10.2

thank you for reply
i command yours , but i get another warning

admins-MacBook-Pro:~ admin$ sudo npm install 

npm WARN admin@1.0.0 No description

npm WARN admin@1.0.0 No repository field.

audited 127 packages in 1.604s

found 0 vulnerabilities
  1. Note. You do not need to use sudo (and should not use sudo) for a local install. So just:
npm install 
  1. Those warnings are about missing fields in the package.json of your project. (Those two are not likely to affect you unless or until you are planning to publish the package, but you might like to supply them just to silence the warnings!)
  1. If you have npm installing global packages to a system owned directory (which is the default), you will need to use sudo when you update npm itself. If you are using a node version manager to install node and npm to a folder you own then you don’t need to use sudo even for global installs.

Here are all three relevant commands, with sudo only needed on the first two

# Fix past problems, just once
$ sudo chown -R $USER ~/.npm
# Upgrade npm. Need sudo if installing to system folder.
$ sudo npm install npm@latest -g
# Local install, do not use sudo
$ npm install 

@shadowspawn, this has the wrong order:

# Fix past problems, just once
$ sudo chown -R $USER ~/.npm
# Upgrade npm. Need sudo if installing to system folder.
$ sudo npm install npm@latest -g
# Local install, do not use sudo
$ npm install 

Correct is:

# Upgrade npm. Need sudo if installing to system folder.
$ sudo npm install npm@latest -g
# Fix past problems, just once
$ sudo chown -R $USER ~/.npm
# Local install, do not use sudo
$ npm install 

In your version, the second ‘sudo npm install’ call will leave root owned files in the cache because it’s executing with the old npm version. The cleanup needs to be after, and is unnecessary before the npm install since EACCES errors don’t occur when running under sudo.

1 Like

Oops, yes, sorry. The wrong-order instructions will run ok, but leave behind ownership problems from the last use of the old npm.

(The chown is needed first if you no longer need to use sudo for the global install, which is much less likely.)

1 Like