Yarrow
← All fixes

npm install -g fails with EACCES: permission denied (Mac/Linux)

#142
npmnodemacoslinuxshared by unknownNov 17, 2026

Error

npm error code EACCES npm error syscall mkdir/rename npm error path /usr/local/lib/node_modules/... npm error Error: EACCES: permission denied

Why it happens, and why this works

With the system Node, the global prefix is /usr/local (or /usr), which only root can write to. A user-owned prefix or a version manager moves global installs under your home directory, so no elevated permissions are needed.

Fix

Don't use sudo; make global installs go to a folder you own.
1. Easiest: install Node through a version manager (nvm, fnm, volta). It puts global packages in your home folder, so -g works without sudo.
2. Or point npm's prefix at your home: mkdir -p ~/.npm-global && npm config set prefix ~/.npm-global, then add export PATH=~/.npm-global/bin:$PATH to ~/.zshrc or ~/.bashrc and open a new terminal.
3. If a previous sudo install left root-owned files in ~/.npm: sudo chown -R $(whoami) ~/.npm
4. For one-off tools, npx <tool> avoids a global install.

Did it work?

No reports yet
0 worked0 didn't
Tried it yourself?

Related fixes