How to fix EACCES issues with npm install

2019-01-15 09:46发布

Some of my node modules get installed but there are always these sort of issues on this particular linux mint machine

npm install 

npm ERR! Error: EACCES, open '/home/me/.npm/semver/3.0.1/package/package.json'
npm ERR!  { [Error: EACCES, open '/home/me/.npm/semver/3.0.1/package/package.json']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/home/me/.npm/semver/3.0.1/package/package.json',
npm ERR!   parent: 'gulp' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

标签: npm
2条回答
SAY GOODBYE
2楼-- · 2019-01-15 10:33

UPDATE. See this answer for a better way.


You have to set correct permissions (ownership) so npm can access your (sub)directories with your normal user permissions:

sudo chown -R $USER <directory>

where in your case <directory> is /home/me and -R is for recursive to also change ownership of all your subdirectories, which is exactly what you want. That should fix the EACCESS issue.

Sadly the advise to run the command as root/Administrator is wrong here.

You want to avoid running npm with sudo ever, as recommended by the npm creator Isaac Schlueter:

I strongly encourage you not to do package management with sudo! Packages can run arbitrary scripts, which makes sudoing a package manager command as safe as a chainsaw haircut. Sure, it’s fast and definitely going to cut through any obstacles, but you might actually want that obstacle to stay there.

See here for more details.

查看更多
Animai°情兽
3楼-- · 2019-01-15 10:38

This code fix it for me.

sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
查看更多
登录 后发表回答