DEV Community

Nishantkora
Nishantkora

Posted on

Permission error : sudo npm i -g node@14.18.1 throws error

Hello everyone

I have node app running with sudo npm start command and

  • when app running its not taking specified node version 14.18.1 - - when i do sudo su and node -v gives "14.18.1" but for normal use sudo node -v gives me "12.22.1"
  • when i try to install sudo npm i -g node@14.18.1 gives me below error
  • aws ec2 linux machine

sudo npm i -g node@14.18.1

node@14.18.1 preinstall /usr/lib/node_modules/node
node installArchSpecificPackage

npm ERR! code EACCES
npm ERR! syscall scandir
npm ERR! path /root/.npm/_logs
npm ERR! errno -13
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug

npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 99:1000 "/root/.npm"
glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
errno: -13,
code: 'EACCES',
syscall: 'scandir',
path: '/root/.npm/_logs'
}
npm ERR! code EACCES
npm ERR! syscall open
npm ERR! path /root/.npm/_cacache/index-v5/14/d7/ea219c5ebc10fb0a36ef7e8846ddffeccbde34792bd22566ab58fbd91ac7
npm ERR! errno -13
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 99:1000 "/root/.npm"
internal/modules/cjs/loader.js:818
throw err;
^

Error: Cannot find module 'node-linux-x64/package.json'
Require stack:

  • /usr/lib/node_modules/node/installArchSpecificPackage.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15) at Function.resolve (internal/modules/cjs/helpers.js:80:19) at ChildProcess. (/usr/lib/node_modules/node/node_modules/node-bin-setup/index.js:19:27) at ChildProcess.emit (events.js:314:20) at maybeClose (internal/child_process.js:1022:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5) { code: 'MODULE_NOT_FOUND', requireStack: [ '/usr/lib/node_modules/node/installArchSpecificPackage.js' ] } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node@14.18.1 preinstall: node installArchSpecificPackage npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the node@14.18.1 preinstall script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2024-01-12T04_18_22_548Z-debug.log

Top comments (0)