Fix: npm install fails with EACCES permission error

Problem When running npm install -g to install packages globally, you encounter: 1 2 3 4 5 npm ERR! code EACCES npm ERR! syscall access npm ERR! path /usr/local/lib/node_modules npm ERR! errno -13 npm ERR! Error: EACCES: permission denied Root Cause npm tries to install global packages in system directories that require elevated permissions. Using sudo works but creates security risks and file ownership issues. Solution Option 1: Change npm’s Default Directory (Recommended) Create a directory for global installations: 1 mkdir ~/.npm-global Configure npm to use the new directory: 1 npm config set prefix '~/.npm-global' Add the new directory to your PATH: For bash users, add to ~/.bashrc or ~/.bash_profile: ...

January 20, 2026 · 2 min · TutorialHub