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.
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'
# 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?
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.
Related Developer Error Solutions
Browse All 69 GuidesNPM: ERESOLVE unable to resolve dependency tree
Resolve strict peer dependency conflicts in npm 7+ using --legacy-peer-deps or updating outdated packages.
npm ERR! gyp ERR! build error / node-gyp rebuild failed
Install the native build toolchain (Python, make, C++ compiler) or switch to prebuilt / pure-JS alternatives to stop node-gyp failures.
Node.js: Error [ERR_MODULE_NOT_FOUND]: Cannot find module
Fix ESM import resolution: add .js extensions to relative imports, install missing packages, and align "type": "module" with your TypeScript output.