---
title: "Error: EACCES: permission denied when installing global npm packages"
description: "npm install -g fails with EACCES when Node was installed into a system folder. Fix it properly with a Node version manager or a user-owned npm prefix, not with sudo."
url: https://www.danny.engineering/answer/nodejs/error-eacces-permission-denied-when-installing-global-npm-packages
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:24:00.000Z
tags: ["Node.js"]
---

# Error: EACCES: permission denied when installing global npm packages

## The short answer


npm is trying to write to a folder owned by the system, usually `/usr/local/lib/node_modules`, and your user cannot write there. Do not reach for `sudo`. Install Node with a version manager so global packages go into your home folder instead.


```bash
# Install nvm (check the nvm README for the current version)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

# Open a new terminal, then
nvm install --lts
npm install -g typescript
```


## Why it happens


The full error looks something like this:


```bash
npm error code EACCES
npm error syscall mkdir
npm error path /usr/local/lib/node_modules/typescript
npm error Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/typescript'
```


Global packages are installed under npm's prefix folder. If you installed Node from the official installer or a Linux package, that prefix is a system location such as `/usr/local` or `/usr`, owned by root. A normal `npm install -g` runs as your user, so it is not allowed to create folders there.


Running `sudo npm install -g` seems to fix it, but it causes new problems:

- Package install scripts run as root, which is a real security risk.
- Files in your npm cache and global folder end up owned by root, so later commands fail with the same error, even without `-g`.
- You end up needing `sudo` for every update.

The npm documentation recommends a Node version manager for exactly this reason.


## How to fix it


### Use a Node version manager


A version manager installs Node inside your home folder, so the global prefix belongs to you. It also lets you switch Node versions per project.

- **nvm** on macOS and Linux, shown in the short answer.
- **fnm**, a fast alternative that also works on Windows.
- **nvm-windows** on Windows.

With fnm:


```bash
fnm install --lts
fnm use lts-latest
npm install -g typescript
```


After switching, check that npm now points at your home folder:


```bash
which node
npm config get prefix
```


Both paths should be inside your home folder. If you previously installed Node system-wide, uninstall that copy so the two do not fight over your `PATH`.


### Or change npm's prefix to a folder you own


If you cannot use a version manager, point npm's global prefix at a folder in your home directory and add its `bin` folder to your `PATH`.


```bash
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global

# Add this line to ~/.zshrc or ~/.bashrc
export PATH="$HOME/.npm-global/bin:$PATH"
```


Open a new terminal and run `npm install -g` again.


### Avoid global installs where you can


Many tools do not need a global install. Add them as dev dependencies so the version is pinned per project, and run them with `npx` or through `package.json` scripts.


```bash
npm install --save-dev typescript
npx tsc --version

# Run once without installing
npx create-vite@latest my-app
```


### Clean up after using sudo


If you already used `sudo`, your npm cache may be owned by root. Give it back to your user:


```bash
sudo chown -R "$(id -u):$(id -g)" ~/.npm
```


## Common pitfalls

- Using `chmod 777` on `/usr/local`. It makes the error go away by making system folders writable by everything on the machine.
- Running `sudo chown` on all of `/usr/local`. Other tools, such as Homebrew, manage parts of it and expect specific ownership.
- Installing nvm but not opening a new terminal, so the old system Node is still first on your `PATH`.
- Mixing a version manager with a system Node install, then wondering why `which npm` points to the wrong one.
- Seeing EACCES inside a project, not a global install. That usually means `node_modules` or `~/.npm` was created by `sudo` earlier; fix the ownership instead of adding more `sudo`.

## Related reading

- [npm Docs: Resolving EACCES permissions errors](https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally)
- [Node.js: Download and install](https://nodejs.org/en/download)
