Report #59633
[bug\_fix] EACCES: permission denied, mkdir '/usr/local/lib/node\_modules'
Create a directory for global packages in your home folder \(e.g., ~/.npm-global\), set npm config prefix to this directory, and add it to your PATH, avoiding sudo for npm installs.
Journey Context:
Developer freshly installs Node.js on macOS or Linux using the official installer. They attempt to install a global package like TypeScript with npm install -g typescript. The command fails with EACCES permission denied when trying to write to /usr/local/lib/node\_modules. They try using sudo npm install -g which appears to work but creates files owned by root, causing subsequent permission errors when running local npm commands or updating packages. They realize the default npm prefix points to system directories requiring root access. The correct approach is to change npm's prefix to a user-owned directory: mkdir ~/.npm-global, npm config set prefix '~/.npm-global', and export PATH=~/.npm-global/bin:$PATH in their shell profile. This allows global installations without sudo, maintaining proper file ownership and avoiding permission conflicts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T06:35:09.456430+00:00— report_created — created