Fix: EACCES: permission denied
Step-by-step fix for 'EACCES: permission denied' errors when running npm install for OpenClaw.
This page helps you fix permission errors during npm install.
🔴 Raw Error Log (What You Actually See)
You may see one or more of these messages:
Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules'
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13Or:
Error: EACCES: permission denied, access '/home/user/.npm'
gyp ERR! stack Error: EACCES: permission deniedIf your error looks similar, you are in the right place.
🔍 Why This Happens (Root Cause)
This error occurs when:
- npm directories are owned by root instead of your user
- You're trying to install packages in a protected system directory
- Previous
sudo npm installcommands created files with wrong ownership
✅ How to Fix It (Step-by-Step)
⚠️ Important: Never use
sudo npm install— it creates more permission problems!
Step 1 — Check If You Used sudo Before
If you previously ran sudo npm install, you need to fix ownership first.
Step 2 — Fix npm Directory Ownership (Mac/Linux)
sudo chown -R $USER:$(id -gn $USER) ~/.npm
sudo chown -R $USER:$(id -gn $USER) ~/.configStep 3 — Fix Project Directory Ownership
Navigate to your OpenClaw project folder and run:
sudo chown -R $USER:$(id -gn $USER) .Step 4 — Reinstall Dependencies
rm -rf node_modules package-lock.json
npm install🔎 Verify the Fix
After applying the fix, run:
npm install✅ Expected Result
The installation completes without EACCES errors:
added 342 packages in 45s❌ Still Not Working?
Best Practice: Use nvm (Node Version Manager)
Using nvm avoids permission issues entirely:
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Restart terminal, then:
nvm install 18
nvm use 18
# Now npm install works without sudo
npm install🧭 Advanced Notes
Windows Users:
If you see permission errors on Windows:
- Close your terminal
- Right-click PowerShell or Command Prompt
- Select "Run as Administrator"
- Try
npm installagain
🔗 Related: Common Errors Summary | Error Dictionary
Internal Ref: ERROR_INSTALL_002