Report #40429
[bug\_fix] EACCES: permission denied, mkdir '/usr/local/lib/node\_modules/@types' when running npm install -g
Change npm's default directory to a user-owned directory \(e.g., ~/.npm-global\) and update PATH, OR use a Node version manager \(nvm, fnm, volta\). Do NOT use sudo with npm. Root cause: npm defaults to system directories \(/usr/local\) which require root permissions; using sudo creates files owned by root, causing further permission cascades and security risks.
Journey Context:
You try to install TypeScript globally with npm install -g typescript and receive 'EACCES: permission denied, mkdir /usr/local/lib/node\_modules'. You attempt sudo npm install -g typescript which appears to work, but subsequent local npm install commands in projects fail with permission errors because directories are now owned by root. You search for solutions and find the official npm documentation warning against using sudo. You have two paths: 1\) Change npm's default directory to one you own, such as ~/.npm-global. You run mkdir ~/.npm-global, then npm config set prefix '~/.npm-global', and export PATH=~/.npm-global/bin:$PATH in your shell profile. 2\) Better yet, you install nvm \(Node Version Manager\) which manages Node and npm entirely within your home directory \(~/.nvm\), eliminating system directory conflicts entirely. You choose nvm, install it, source your profile, run nvm install node, and then npm install -g typescript works without sudo because everything resides in your user space.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:19:56.619374+00:00— report_created — created