npm ERR! code EACCES: permission denied, mkdir '/usr/local/lib/node_modules'
TL;DRnpm cannot create a folder it needs because it lacks permission to write in a protected system directory.
Most likely cause: npm is attempting a global install into a system folder that requires elevated rights
Try first: Install the package inside your current project instead of globally
Likely causes
- npm is attempting a global install into a system folder that requires elevated rightsmost likely
- the target folder has restrictive ownership or permissions set by the operating systempossible
How to fix it
Safest first: SafeChanges settingsDangerous
Install the package inside your current project instead of globallySafe
Run your npm install command without the -g flag so files go into a folder you already own.
Run the install command with elevated permissionsChanges settings
Prefix the command with sudo to temporarily allow writing to the system folder.
sudo npm install -g <package-name>⚠ This grants temporary admin rights; only do this if you understand the command.
If that didn't fix it
Global npm package installs will continue to fail.
When to see a technician
If you are unsure about using sudo or changing system folder permissions, consult a technician.
Related errors
codenpm ERR! code ENOENTcodenpm ERR! code ERESOLVEcodenpm ERR! code ENOENT: no such file or directory, open 'package.json'codenpm ERR! code ERESOLVE unable to resolve dependency treecodeError: Cannot find module (node:internal/modules/cjs/loader)codepermission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock