Tag Archives: Test environment setup

[Solved] npm install Error: Error: EACCES: permission denied

Questions

When: NPM install @sentry/cli -g is executed as root, an error is reported:

npm ERR! Error: EACCES: permission denied, mkdir '/root/.npm/sentry-cli'

Cause

npm does not support running as root for security reasons. Even if you run it as root, npm will automatically redirect to a user named nobody, who has almost no privileges. In this case, if there are operations in the script that require permissions, such as writing files (especially to /root/.node-gyp), it will crash.

To avoid this, either follow the npm rules and create a privileged user specifically for running npm, or add the –unsafe-perm argument so that it doesn’t switch to nobody and runs as whatever user it is, even if it’s root.

 

Solution

Add parameter after executing command: –unsafe-perm

npm install --unsafe-perm @sentry/cli -g