Developer & npm Errors

How to Fix npm EACCES Permission Denied Errors

By ErrorNest Published 3 min read
The npm EACCES error means npm cannot write to a folder you do not own. Avoid sudo and use a version manager or a user-owned global folder instead.
Programming code on a laptop screen
On this page

The npm error EACCES: permission denied means npm tried to write to a folder your user account does not own. It usually appears when you install a package globally with npm install -g, and it often names a path such as /usr/local/lib/node_modules. The common reaction is to add sudo, but that causes more permission problems later. There are safer fixes.

npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13

Quick fix: Do not use sudo npm. Either reinstall Node with a version manager such as nvm (option A), or change npm’s global folder to one in your home directory (option B).

What causes EACCES in npm

  • Node was installed system-wide, so the global folder belongs to root.
  • An earlier sudo npm install left files owned by root in your project or in ~/.npm.
  • A project folder that sits in a location your user cannot write to.
Laptop with a code editor open on a desk

1. Read the path in the error

The line starting with path tells you where npm failed. A path under /usr/local/lib or /usr/lib points to the global folder. A path inside your project or ~/.npm points to ownership problems from an earlier sudo install.

2. Option A: use a Node version manager

A version manager installs Node in your home folder, so global installs never need elevated permissions. Install nvm by following its instructions, then:

nvm install --lts
nvm use --lts

Open a new terminal and run your npm install -g command again. This is the cleanest long-term fix.

3. Option B: change the global folder

If you want to keep your current Node install, point npm at a folder you own:

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'

Then add the new folder to your path. Add this line to ~/.profile (or ~/.zshrc on macOS) and reload it:

export PATH=~/.npm-global/bin:$PATH
source ~/.profile

Run your global install again. Programs you installed before the change stay in the old folder, so reinstall any you still need.

4. Fix ownership left behind by sudo

If the error is inside ~/.npm or your project’s node_modules, an earlier sudo made root the owner. Change ownership back to your user:

sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) node_modules

Warning: Run chown -R only on folders you recognise, and check the path before pressing Enter. A wrong path can change ownership of system files. For a project folder, you can also delete node_modules and run npm install again.

5. Check that the project folder is writable

Make sure the project is not inside a protected folder or a read-only drive. Move it to a folder under your home directory if needed.

6. If you see EPERM on Windows

On Windows the equivalent error is usually EPERM. Close editors and terminals that may hold files open, pause antivirus scanning of the project folder briefly, and try again in a terminal opened as administrator.

Frequently asked questions

Is it safe to use sudo with npm?

It works once but is discouraged. It can leave root-owned files that cause the same error again, and running install scripts as root is a security risk.

Does this delete my projects?

No. These fixes change folders and ownership, not your source code. Back up before running any chown command.

When to contact support

If the error continues, check that you are on a supported Node version with node -v and npm -v, and search the npm documentation for your exact message. If the failure is a dependency conflict instead, read how to fix npm ERESOLVE errors.