Report #42230
[bug\_fix] npm ERR\! code EACCES npm ERR\! syscall mkdir npm ERR\! path /usr/local/lib/node\_modules
Change npm's default directory to one owned by your user: 'mkdir ~/.npm-global && npm config set prefix '~/.npm-global'' then add the new directory to your PATH in ~/.bashrc or ~/.zshrc.
Journey Context:
You get a new MacBook, install Node from the official installer package. Excited to use TypeScript globally, you run 'npm install -g typescript'. It immediately fails with 'EACCES: permission denied, mkdir /usr/local/lib/node\_modules/typescript'. You remember using sudo for Python pip, so you try 'sudo npm install -g typescript'. It appears to work but takes forever and feels wrong. Later, you encounter weird permission issues with npm cache and suspect you've corrupted the npm prefix ownership. Researching reveals that npm's default global directory \(/usr/local/lib/node\_modules\) is owned by root on macOS when installed via the installer, but you shouldn't use sudo with npm due to security risks and future permission nightmares. The proper fix is to change npm's default directory to one in your home folder. You run 'mkdir ~/.npm-global', then 'npm config set prefix '~/.npm-global'', then add '~/.npm-global/bin' to your PATH in ~/.zshrc. After reloading the shell, 'npm install -g typescript' works without sudo because it writes to your home directory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T01:21:24.045831+00:00— report_created — created