Skip to content
Node.js and Python2 min read

npm ERR! code EACCES (permission denied)

npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules'

Short answer

npm EACCES means npm tried to create or change files in a folder your user has no permission to write, most often the global `node_modules` directory or a `~/.npm` cache created earlier with sudo. Don't fix it with sudo: install packages locally or use `npx`, point npm's global prefix to your home folder, and correct ownership of the folders involved.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. Causes
  2. How to fix it
  3. Prevention
  4. On ArabyHost

EACCES is the operating system’s “permission denied” code. npm reports it when it needs to create a folder, write a file or run a script somewhere your user account can’t write to. The path line in the error is the key: it tells you whether the problem is the global install folder, npm’s cache, or your project itself. Newer npm versions print the same thing as npm error code EACCES.

Causes

  • A global install (npm install -g) into a system folder such as /usr/local/lib/node_modules or /usr/lib/node_modules, which belongs to root.
  • An earlier sudo npm install that left root-owned files in ~/.npm or in the project’s node_modules.
  • Project files owned by another user, for example after uploading or copying them as a different account.
  • Wrong file permissions, such as a folder without write permission for its owner.
  • On shared hosting, trying to install into system folders, which no customer account can write to.

How to fix it

  1. Read the path line and decide which of the cases below it matches.

  2. Global folder: don’t install globally. Run tools with npx, or install them per project:

    npx some-cli --help
    npm install --save-dev some-cli
  3. If you really need global packages, move npm’s global prefix into your home folder:

    mkdir -p ~/.npm-global
    npm config set prefix ~/.npm-global
    echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc
    source ~/.bashrc

    On your own computer, a Node version manager such as nvm does the same thing automatically.

  4. Cache owned by root (~/.npm): on your own machine, run the chown command npm suggests in the error, then retry.

  5. Project folder: check ownership with ls -la. Remove the broken install and reinstall as your normal user:

    rm -rf node_modules
    npm ci

    If rm itself is denied, the files belong to another user; fix ownership first (on your PC with sudo chown -R, on hosting ask support).

  6. Permissions: folders usually need 755 and files 644. The chmod calculator explains the numbers.

For permission errors outside npm, see permission denied writing files.

Prevention

  • Never use sudo with npm in a project folder.
  • Prefer project-local dev dependencies and npx over global installs.
  • Upload project files as the same user that runs the app.

On ArabyHost

On ArabyHost AI/Developer plans, SSH runs inside a CloudLinux CageFS jail without root access, so system folders can’t be written and sudo isn’t available. That’s expected, not a fault: install packages locally in your project, use npx, or set the npm prefix to your home folder as shown above. For apps created in Setup Node.js App, enter the app’s environment with the command shown on its page (or use the Run NPM Install button), and npm installs into the app’s own environment with your user’s permissions. The SSH access guide covers connecting.

FAQ

Why shouldn't I use sudo npm install?

It runs package install scripts as root and leaves root-owned files in your project and cache, which causes the next EACCES. On shared hosting it isn't available anyway.

How do I run a CLI tool without installing it globally?

Use `npx tool-name`, or add it to the project with `npm install --save-dev tool-name` and call it from a script in `package.json`.

The error mentions ~/.npm/_cacache. What now?

Your cache contains files owned by another user, usually root after a sudo install. On your own machine, run the `chown` command npm prints in the error to give the folder back to your user.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.