Report #10700
[bug\_fix] npm ERR\! code EACCES
Do not use \`sudo\`. Instead, change npm's default directory to one owned by the current user: \`mkdir ~/.npm-global\`, \`npm config set prefix '~/.npm-global'\`, and add \`export PATH=~/.npm-global/bin:$PATH\` to \`~/.bashrc\` \(or use a Node version manager like nvm/fn which handles this automatically\).
Journey Context:
You just installed Node.js from the official macOS installer or Linux package manager. You try to install TypeScript globally: \`npm install -g typescript\`. It fails with "EACCES: permission denied, mkdir '/usr/local/lib/node\_modules/typescript'". You think you need admin rights, so you try \`sudo npm install -g typescript\`. It works, but now you have files in \`/usr/local\` owned by root. Later, when you run \`npm update -g\`, you get more permission errors. You try to change ownership with \`sudo chown -R $\(whoami\) /usr/local\`, which breaks Homebrew or other system tools. The root cause is that npm defaults to a system directory for global packages. The correct fix is not using sudo, but telling npm to use a directory in your home folder. You create \`~/.npm-global\`, set it as the prefix, and add it to your PATH. Even better, you uninstall the system Node and install nvm or fnm, which manages Node versions and global packages entirely within \`~/.nvm\`, avoiding permission issues entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:22:11.036752+00:00— report_created — created