npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Can't install npm packages without sudo

When I try to install some npm packages for my project, I get an error.

pm WARN checkPermissions Missing write access to /home/vlado/Desktop/marpit/node_modules
npm WARN marpit@1.0.0 No description
npm WARN marpit@1.0.0 No repository field.

npm ERR! path /home/vlado/Desktop/marpit/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access ‘/home/vlado/Desktop/marpit/node_modules’
npm ERR! [Error: EACCES: permission denied, access ‘/home/vlado/Desktop/marpit/node_modules’] {
npm ERR! stack: “Error: EACCES: permission denied, access ‘/home/vlado/Desktop/marpit/node_modules’”,
npm ERR! errno: -13,
npm ERR! code: ‘EACCES’,
npm ERR! syscall: ‘access’,
npm ERR! path: ‘/home/vlado/Desktop/marpit/node_modules’
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR! /home/vlado/.npm/_logs/2019-07-25T17_03_31_527Z-debug.log

Platform Info

$ npm --versions

marpit: ‘1.0.0’,
npm: ‘6.10.2’,
ares: ‘1.15.0’,
brotli: ‘1.0.7’,
cldr: ‘35.1’,
http_parser: ‘2.8.0’,
icu: ‘64.2’,
llhttp: ‘1.1.4’,
modules: ‘72’,
napi: ‘4’,
nghttp2: ‘1.39.1’,
node: ‘12.7.0’,
openssl: ‘1.1.1c’,
tz: ‘2019a’,
unicode: ‘12.1’,
uv: ‘1.30.1’,
v8: ‘’,
zlib: ‘1.2.11’

$ node -p process.platform

My guess is that you did sudo npm install locally in your project prior to upgrading to npm 6.10.2.

This should fix it permanently:

sudo chown -R $USER /home/vlado/Desktop/marpit
sudo chown -R $USER /home/vlado/.npm

Yes, it fixed the problem, but now I have to do this for EVERY SINGLE PROJECT???

Well, chown -R is recursive, so you could just run it on your home directory and hit them all at once.

Yes, but when I create another project, I have to do this again. It is not a fix. DRY.

If you update to 6.10.2, then no, you won’t have to do it each time, because the root cause bug has been fixed.

Also, if you’re installing locally, you shouldn’t have to use sudo at all anyway.

If you do still have to fix the file ownership after you “create another project”, how are you creating the new project?