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.
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
codeSyntaxError: Cannot use import statement outside a modulecodeTypeError: Cannot read properties of undefined (reading 'map')codedocker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?codePermission denied (publickey). fatal: Could not read from remote repository.codegit push: error: failed to push some refs (rejected, non-fast-forward)