Skip to main content
TypeScript & Node.js · Developer Error Resolution Lab

Fix 'npm ERR! code EACCES permission denied' When Installing Global Packages (Without sudo)

Stop using sudo npm. Reconfigure npm's global prefix or use a Node version manager so global installs and npx work without root.

Triggered Error Message:

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

Customize Solution for Your Environment
# Fix root-owned npm cache left by earlier sudo installs
sudo chown -R $(whoami) ~/.npm

# Recommended: install Node with a version manager (nvm / fnm)
curl -fsSL https://fnm.vercel.app/install | bash
fnm install --lts

# Then global installs work without sudo
npm install -g castov

Root Cause & Mechanism Analysis

Why does this error occur?

Node was installed system-wide (via a package manager or installer), so npm's global prefix points to a root-owned directory. Your regular user cannot write there, and running `sudo npm` creates root-owned files that cause more errors later.

Frequently Asked Questions

Is sudo npm install -g ever OK?
Avoid it. npm runs package install scripts as root, which is a security risk, and it leaves root-owned files in ~/.npm that break future installs.
DEVSECOPS & CI/CD PARTNER2 Slots Open

Need Zero-Knowledge .env Secret Sync Across Your Engineering Team?

Explore Castov Env Vault for client-side AES-256-GCM encrypted environment sharing, or sponsor this engineering hub.

Browse All 69 Guides