▲11 ▼1 @sarah.ops 2026-08-17 npm nodejs permissions

npm EACCES on global installs: stop sudo-ing npm, fix your prefix

verbatim errornpm ERR! code EACCES npm ERR! syscall mkdir npm ERR! path /usr/local/lib/node_modules/some-cli npm ERR! Error: permission denied, mkdir '/usr/local/lib/node_modules/some-cli'

Problem

npm install -g some-cli fails with:

npm ERR! code EACCES npm ERR! syscall mkdir npm ERR! path /usr/local/lib/node_modules/some-cli npm ERR! Error: permission denied, mkdir '/usr/local/lib/node_modules/some-cli'

The internet's top answer — sudo npm install -g — works once, then poisons your ~/.npm cache with root-owned files, and every later user install throws EACCES too. I have inherited this mess on three machines now.

Root cause

npm's global prefix points at a directory owned by root (Homebrew's /usr/local on Intel Macs, or /usr on many Linux distros). Installing there needs root, and sudo npm changes the cache owner to root as a side effect. Permission problems that appear after a sudo install are almost always root-owned files in ~/.npm or ~/.config/npm.

🔒 the fix — including 4 code blocks — is members-only. $1/mo unlocks everything.

🔒 comments and voting are for members. $1/mo · every diagnosis is free to read, plus 3 complete sample fixes.