Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm install -g fails with EACCES on /usr/local/lib/node_modules

Errornpm error code EACCES

Short answer

EACCES means npm tried to write global packages into a folder your user does not own, usually /usr/local/lib/node_modules. Do not fix it with sudo or chmod on system folders. Point npm's prefix at a folder in your home directory, add its bin folder to PATH, and install again.

  • Applies to npm 10, Node.js 22, macOS, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out where global installs go and who owns that folder. If the owner is root and you are not, you have found the problem.

    npm config get prefix
    ls -ld "$(npm config get prefix)/lib/node_modules"
  2. 2Match what you see, then jump to its fix

    1. 1path /usr/local/lib/node_modules (or /usr/lib/node_modules) in the errorThe global prefix is a system folder owned by rootFix
    2. 2The install works, but the command is then 'command not found'You use zsh and the new PATH line is never readFix

What does the error look like?

  • npm error code EACCES
  • npm error syscall access
  • npm error path /usr/local/lib/node_modules
  • Error: EACCES: permission denied, access '/usr/local/lib/node_modules'

Cause 1 of 2

The global prefix is a system folder owned by root

1Check

By default npm's prefix is where Node.js is installed, often /usr/local. A Node.js installed by a system package or an installer leaves that tree owned by root.

npm config get prefix

2Fix

Give npm a prefix inside your home folder and put its bin folder on PATH. Then global installs never need elevated rights. On Windows this method does not apply.

npm config set prefix ~/.local
echo 'PATH=~/.local/bin:$PATH' >> ~/.profile
source ~/.profile

3Verify

Install a global package without sudo and run it.

npm install -g npm-check-updates
ncu --version

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 2

You use zsh and the new PATH line is never read

1Check

zsh login shells read ~/.zprofile, not ~/.profile. Check your shell and whether the new folder is on PATH.

echo $0
echo $PATH | tr ':' '\n' | grep local

2Fix

Load the profile from the zsh profile file, then reload it.

echo 'source ~/.profile' >> ~/.zprofile
source ~/.profile

3Verify

The folder shows up in PATH in a new terminal.

echo $PATH | tr ':' '\n' | grep local

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Never use sudo with npm install; a root-owned file will cause the next EACCES.
  • Install Node.js through a version manager or an installer that keeps its files in your home folder.
  • For one-off tools, run them with npx instead of installing them globally.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.