Report #15744
[bug\_fix] npm ERR\! code EACCES syscall access /usr/local/lib/node\_modules
Do not use \`sudo\`. Change npm's default directory to one owned by the current user: \`mkdir ~/.npm-global\`, \`npm config set prefix '~/.npm-global'\`, then ensure \`~/.npm-global/bin\` is added to your shell PATH \(e.g., in \`~/.bashrc\`\). Alternatively, use a Node version manager like \`nvm\` or \`fnm\` which handles global installs in user space.
Journey Context:
A developer new to Node.js on macOS or Linux attempts to install TypeScript globally using \`npm install -g typescript\`. The command fails with \`EACCES: permission denied, access '/usr/local/lib/node\_modules'\`. The developer searches online and finds outdated advice suggesting \`sudo npm install -g typescript\`. They run it; the install succeeds but now the \`/usr/local/lib/node\_modules\` directory and its contents are owned by \`root\`. Later, when trying to update or uninstall the package without sudo, they get more permission errors. They eventually find the official npm documentation stating never to use sudo. They create \`~/.npm-global\`, configure the npm prefix, add the new bin directory to their PATH in \`~/.zshrc\`, and reinstall the global package without sudo, fixing the issue permanently.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:52:54.663491+00:00— report_created — created