Skip to content

npm and Node.js error

npm: “EACCES: permission denied”

npm install -g (or sometimes a plain npm install) fails with npm error code EACCES and permission denied, mkdir or access, followed by a path such as /usr/local/lib/node_modules. npm tried to write to a folder your user does not own. That happens when Node.js was installed system-wide, or when an earlier sudo npm left root-owned files behind.

Rather hand it over? App Fix Ticket: One reproducible bug in an existing mobile or web app, diagnosed and fixed.The Fix is $1,200 in total. The $450 Diagnosis is optional and credited toward it.

Full refund if Simon can’t take it on once he sees your project, or if you cancel before work starts. Refund terms.

Short answer

For global installs, reinstall Node.js with a version manager such as nvm, fnm or Volta, so global packages go into your home folder. Or point npm’s global folder at a folder you own with npm config set prefix ~/.local and add ~/.local/bin to your PATH. Don’t fix it with sudo npm install -g, which creates more root-owned files. If a normal install in a project fails, root-owned files in the project or in ~/.npm are the cause: change their owner back to your user.

Rather not fix it yourself? App Fix Ticket fixes one reproducible bug at a fixed price, with an optional Diagnosis that is credited toward the fix.

Why npm can’t write there, and the fix

  1. 01

    Node.js is installed system-wide

    “Reinstall npm with a node version manager (recommended), or Manually change npm's default directory” npm Docs, Resolving EACCES permissions errors when installing packages globally

    An installer from nodejs.org or a system package puts global packages in a folder owned by root, so npm install -g fails for your user. A version manager installs Node.js in your home folder, where npm can write. You don’t need to remove the old Node.js first.

    # nvm (macOS and Linux)
    nvm install --lts
    nvm use --lts
    npm install -g npm-check-updates   # no sudo
  2. 02

    Keep Node.js, change npm’s global folder

    “To minimize the chance of permissions errors, you can configure npm to use a different directory.” npm Docs, Resolving EACCES permissions errors when installing packages globally

    If you can’t switch to a version manager, tell npm to put global packages in a folder you own and add its bin folder to your PATH. This does not apply on Windows. If you later switch to nvm, run npm config delete prefix first, because nvm does not work with a custom prefix.

    npm config set prefix ~/.local
    # add to ~/.zshrc (zsh) or ~/.profile (bash), then open a new terminal:
    export PATH="$HOME/.local/bin:$PATH"
  3. 03

    Root-owned files from an earlier sudo

    Running sudo npm install once leaves files owned by root in the project’s node_modules or in the npm cache, and later installs without sudo fail on them. Give them back to your user, then install again without sudo. Run the second line from the project folder; it also covers package-lock.json.

    sudo chown -R "$(whoami)" ~/.npm
    sudo chown -R "$(whoami)" ./node_modules ./package-lock.json
  4. 04

    Run the tool without installing it globally

    Many tools don’t need a global install at all. npx runs a package from the registry or the project, and a project dev dependency keeps everyone on the same version.

    npx create-vite@latest my-app
    npm install --save-dev prettier && npx prettier --check .

Checked against the vendor’s docs on : npm Docs: Resolving EACCES permissions errors when installing packages globally.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

“Very responsive, attentive to fixing bugs, and completed the project as needed! Thank you!”
A buyer in the United States, July 2022. Shopify on Fiverr
Read 126 of the 127 Fiverr reviews

Related: Node.js “Cannot find module” · Node.js ENOENT: no such file or directory · Node.js ERR_OSSL_EVP_UNSUPPORTED

Questions

More on this error

Why not just use sudo?

sudo makes npm run package install scripts as root and leaves root-owned files behind, which cause the next EACCES and are a security risk. Fix the folder ownership or the install location once instead.

Does this happen on Windows?

Rarely in the same form. On Windows, EACCES or EPERM usually means a file is locked by an editor, antivirus or a running dev server: close it and install again.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it. If you already know the cause, you can pay for the fix directly; if not, start with a written diagnosis, which is credited toward the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

A different error?

Ask Simon for a price range

Send the error and what you were doing. Simon replies by email, usually within one business day, with a price range.