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.
Why npm can’t write there, and the fix
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 sudo02
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"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.json04
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.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.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.See scope and start
Related: Node.js “Cannot find module” · Node.js ENOENT: no such file or directory · Node.js ERR_OSSL_EVP_UNSUPPORTED