npm ERR! code EACCES: fix global installs without sudo
Stop using sudo and give npm a user-owned global directory instead.
npm cannot write to the global install directory. Do not use sudo: reinstall Node with a version manager (recommended) or point npm's prefix at a directory you own.
Try these fixes in order
Confirm it is a global-install permission error
Confirm the command included -g and read the path in the EACCES message. A local project install failing with EACCES is a different problem, usually a root-owned node_modules from a past sudo install.
Reinstall Node with a version manager (recommended)
The npm documentation recommends installing Node through a version manager such as nvm, fnm, or Volta. This places global packages under your home directory and avoids permission issues entirely.
Or point npm's prefix at a directory you own
Alternatively, create ~/.npm-global, run npm config set prefix ~/.npm-global, and add ~/.npm-global/bin to your shell PATH. Then install the package globally without sudo and verify the command is found.
npm config set prefix ~/.npm-globalReinstall without sudo and verify
Run the original npm install -g <package> without sudo and confirm the installed command runs. If it worked before only with sudo, remove the root-owned copies to avoid shadowing.
Interpret what you see
The error appears on npm install -g and names a system path
What it suggests: npm tried to write into a system-owned global bin or lib directory, which is the standard EACCES scenario the npm docs address.
Next check: Confirm the failing command used -g and note the path in the EACCES error.
You want a permanent fix rather than a per-command workaround
What it suggests: A version manager installs Node and npm under your home directory, so global installs never need elevated permissions.
Next check: Follow the npm docs' recommended path: install Node through nvm, fnm, or Volta, then reinstall the global package.
You prefer to keep the current Node installation
What it suggests: Changing npm's prefix redirects global installs to a directory you own, without touching the system Node installation.
Next check: Run npm config set prefix ~/.npm-global, add ~/.npm-global/bin to PATH, and retry without sudo.
Why this happens
- Node.js was installed with system-wide directories owned by root or Administrator.
- The npm global prefix points at a system directory the current user cannot write to.
Still not working?
Using sudo with npm can create root-owned files inside your home directory's npm cache, which then breaks later installs run as your normal user. If you already used sudo, check ownership of ~/.npm and fix it before changing the prefix strategy.
Official sources
These steps are based on the linked documentation and general diagnostics. BugMedic has not independently tested every product and system configuration. Review commands before running them.