Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix EACCES issues with npm install

Tags:

npm

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.
like image 702
FutuToad Avatar asked Aug 13 '14 16:08

FutuToad


People also ask

What is Eacces error?

If you encounter “Error: EACCES: permission denied” while installing Typescript or any other program, it is due to permission problems. npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules' In short, that means you do not have permission to install.

Why npm install is not working?

The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.


2 Answers

This code fix it for me.

sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
like image 136
krozero Avatar answered Oct 04 '22 19:10

krozero


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.

like image 22
Dmitri Zaitsev Avatar answered Oct 04 '22 18:10

Dmitri Zaitsev