Home/Troubleshooting/npm install -g fails with EACCES, pip install with externally-managed-environment

npm install -g fails with EACCES, pip install with externally-managed-environment

Updated · airankrush

Symptom

npm install -g for some command-line tool reports EACCES: permission denied. Or pip install reports error: externally-managed-environment and refuses to install.

Possible causes (most common first)

  1. npm's global directory sits under a system path that your account does not own, so an ordinary user cannot write to it.
  2. Python was installed by the system or a package manager and is marked as “externally managed”. Under the Python packaging specification, pip refuses to install into such an interpreter outside a virtual environment, so it does not break other software that depends on it.
  3. Packages were installed with elevated privileges in the past, leaving files in the cache directory that you do not own, and later installs as an ordinary user fail as a result.

Troubleshooting steps (easiest first)

  1. npm: prefer a Node version manager

    The official npm documentation lists this as the first choice: reinstall Node and npm with a version manager (nvm, fnm and similar). Node and the global packages then live in your home folder, which avoids the permission problem at its source and makes switching Node versions between projects easy. You do not need to uninstall the existing Node first.

  2. npm: or change the global directory

    If you would rather keep your current install, change npm's default directory as the same document describes: run npm config set prefix ~/.local and add the line PATH=~/.local/bin:$PATH to ~/.profile. With zsh, the macOS default, also add the line source ~/.profile to ~/.zprofile. Open a new terminal and install the global package again.

  3. Python: use a virtual environment

    The approach given by the Python packaging specification is to install project dependencies into a virtual environment. In the project folder run python3 -m venv .venv, then source .venv/bin/activate. Every pip install after that goes into this folder, and deleting the folder leaves nothing behind.

  4. Python: use pipx for command-line tools

    If what you want is a globally available command-line program and not a library, use pipx. It creates a separate virtual environment for each program and puts the command on your PATH. pipx itself can be installed with Homebrew.

  5. Do not force it with the override flag

    The error message mentions the --break-system-packages flag. The specification itself positions it as a risky override, and the name is the warning. On a machine meant to run tasks for a long time, a damaged system Python takes a lot of time to track down. For the same reason, do not run npm or pip with elevated privileges just to get past the error.

When to contact support directly

These problems can almost always be solved inside your own home folder, so you normally do not need support. The exceptions: your home folder itself is not writable (for example ~/.npm or ~/.local is not owned by you and you cannot change it back with your own account), or the install fails because the disk is full. Contact support on Contact support with your machine ID, the full failing command and error text, and the output of ls -ld on the folder that fails.

FAQ

What if I get EACCES while installing Claude Code?

The approach is the same: do not install with elevated privileges. For Claude Code's install methods and troubleshooting steps, follow the install troubleshooting page in its official documentation.

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · All troubleshooting pages