Report #75821
[bug\_fix] npm ERR\! code EACCES npm ERR\! syscall access npm ERR\! path /usr/local/lib/node\_modules
Change npm's default directory to a user-owned path: \`mkdir ~/.npm-global && npm config set prefix '~/.npm-global'\`, then add \`~/.npm-global/bin\` to PATH in \`.bashrc\`/\`.zshrc\`. Alternatively, use \`npx\` instead of global installs. Root cause: npm defaults to system directories \(\`/usr/local\`\) which require root write access; using \`sudo\` with npm creates root-owned files that break future non-sudo operations.
Journey Context:
Developer attempts to install TypeScript globally with \`npm install -g typescript\` on a fresh macOS or Linux machine. It fails immediately with \`EACCES: permission denied, access '/usr/local/lib/node\_modules'\`. They recall using \`sudo\` for other commands and try \`sudo npm install -g typescript\`. This appears to succeed, but later when they try to update the package or use npm without sudo, they get permission errors on \`~/.npm\` cache or the global directory. They search and find the npm documentation stating that using sudo with npm is strongly discouraged because it creates files owned by root that the user cannot modify later. The correct fix is to change npm's prefix to a directory the user owns \(e.g., \`~/.npm-global\`\), add that to PATH, and never use sudo again. They follow the steps, reinstall the package without sudo, and it works correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:51:40.488453+00:00— report_created — created