npm ERR! code EACCES: check the global prefix, then change it or use a version manager
Frank Zhang
- 4 minutes read - 1728 wordsTL;DR
This error means npm cannot write to the current global prefix, often under /usr/local/lib/node_modules. It is not command not found, and it is not a PATH lookup failure. General guidance, not a first-hand session.
Read the path in the error and the prefix from npm prefix -g, then do one of the two official fixes: reinstall npm with a Node version manager (recommended), or change the prefix to a directory you can write to (the docs use ~/.local). Do not start with sudo npm install -g, and do not change permissions on system directories so you can write to /usr/local. This page is general guidance, not a record of one session. The commands were not re-run for this page. There is no first-hand screenshot of the error. The sources are the npm docs as read on 2026-12-01. If npm help, npm prefix -g, or the text on your screen disagrees with this page, trust that copy.
This is the kind of output people paste, usually right after npm install -g <package>:
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/<package>
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/<package>'
The syscall may instead be rename, open, or symlink, and the path is not always under /usr/local. The block above is a common shape only; the package name is a placeholder, not something from a session on this site. It means npm tried to create or change a file in the current global prefix and the current user could not write there. Resolving EACCES permissions errors when installing packages globally, as read on 2026-12-01, is written for that case. Downloading and installing packages globally, read the same day, says that if you get an EACCES permissions error on a global install, you may need to reinstall npm with a version manager or manually change npm’s default directory.
Which errors this page covers
This page is for npm ERR! code EACCES and EACCES: permission denied, including the mkdir / rename / syscall mkdir wording that shows up in autocomplete, especially when the path is a node_modules directory under the global prefix (on Unix, usually {prefix}/lib/node_modules, for example /usr/local/lib/node_modules). On 2026-12-01, en-US Google autocomplete returned 10 suggestions for npm EACCES permission denied (including mkdir, rename, and npm install) and 10 for npm error code EACCES (including mac, windows, docker, and syscall mkdir / rename / open / symlink). zh-CN Google returned the same English roots, including mkdir '/ usr local lib node_modules, mac npm eacces permission denied, and “how to fix” wording. Bing also had mac npm permission denied, npm error code eacces, and a Chinese “fix npm global EACCES on Linux” phrasing.
It is not for:
- A global CLI that is already installed and works in your terminal, but prints
command not foundin an AI agent, a script, or a non-interactive shell. That is a Node prefix / interactive-versus-non-interactive mismatch; see command not found after npm install -g: your terminal and the AI agent are using different Node installs. This page is about a permissions error that happens before the global directory is written, not a command that cannot be found onPATH. zsh: command not found: brew. That is Homebrew missing fromPATH; see zsh: command not found: brew on Mac: check the prefix, then fix PATH.listen EACCES: permission denied. That is a process failing to bind a port it is not allowed to use, notnpm install -gwriting to the global prefix.- An error path inside a container project directory, such as
/app/node_modules. That is the container user versus a mounted volume. This page does not cover Docker. - An error code of
EPERMrather thanEACCES. Do not assume this page applies. Trust thecodeon your screen.
Read-only: look at the path and the current prefix
npm folders, as read on 2026-12-01, says the prefix config defaults to the location where Node is installed: /usr/local on most systems, and %AppData%\npm on Windows. With the global flag, Unix global packages go to {prefix}/lib/node_modules, executables are linked into {prefix}/bin, and that bin directory needs to be on PATH. Do not assume your prefix is /usr/local: a Homebrew-installed Node on Apple Silicon often uses a different prefix. Trust the output on your machine.
In a terminal, start read-only:
npm prefix -g
npm config get prefix
command -v npm
command -v node
ls -ld "$(npm prefix -g)"
ls -ld "$(npm prefix -g)/lib/node_modules"
Compare those results with the path and syscall in the error. A common case is that npm prefix -g points at /usr/local (or wherever Node is installed on your system), ls -ld shows that directory is not writable by the current user, and the error path sits under that same prefix.
That only means this npm cannot write to its global prefix. It is not proof that npm is broken, and it is not a reason to reinstall Node as root. If the owner you see with ls -ld matches the error path, use the official fixes in the next sections. Do not change permissions on system directories.
On Windows the default prefix is %AppData%\npm. The official “manually change npm’s default directory” section does not apply to Microsoft Windows; see below. The read-only commands on this page are for Unix and macOS.
Official recommendation: reinstall npm with a Node version manager
Resolving EACCES lists “reinstall npm with a node version manager” first, and calls it the best way to avoid permissions issues. The steps point to Downloading and installing Node.js and npm on the same site. That page strongly recommends a Node version manager (nvm or n on macOS or Linux; nodist or nvm-windows on Windows). It does not recommend a Node installer, because the installer puts npm in a directory with local permissions and can cause permissions errors when you run npm packages globally. It also says you do not need to remove your current npm or Node.js before installing a version manager.
Use the official install instructions for the manager you choose; this page does not copy an install script. After it is installed, open a new terminal and check:
command -v node
command -v npm
npm prefix -g
npm prefix -g should now be a path under your home directory, managed by the version manager, not the system directory that could not be written. Then verify with a global install without sudo. The official example is:
npm install -g npm-check-updates
ncu -g
That package is only the docs’ test example. You do not have to install npm-check-updates; you can use a global command you actually need. If this step succeeds, but an AI agent or a non-interactive shell later prints command not found, leave this page and read command not found after npm install -g: your terminal and the AI agent are using different Node installs.
The other official fix: change the default directory (not for Windows)
If you do not want a version manager, the official docs also describe changing npm’s default directory. That section does not apply to Microsoft Windows.
The example uses the hidden directory ~/.local in your home directory (this is the wording and path as read on 2026-12-01; do not substitute a blog path such as ~/.npm-global unless you know why you are doing that). The steps are:
- Point npm at the new directory:
npm config set prefix ~/.local
- Add this line to
~/.profile:
PATH=~/.local/bin:$PATH
If you are using zsh (the docs suggest checking with echo $0), also add this line to ~/.zprofile:
source ~/.profile
- Load the change in the current session:
source ~/.profile
- Test with a global install that does not use sudo. The docs still use
npm install -g npm-check-updates, thenncu -g.
Read the result again:
npm prefix -g
echo "$PATH"
command -v npm
npm prefix -g should be the expanded ~/.local path, and PATH should include the matching bin directory. If a new window works and the old one still prints EACCES, the old session has not loaded the new config. That is not a second failed install.
The same official page notes that if you are on npm 5.2 or later and only need a command occasionally, npx is an alternative to installing it globally. See that page, and npx. That is for “run it once in a while,” not for leaving a command on PATH permanently.
What not to do first
- Do not start with
sudo npm install -g. Neither official fix uses that step, and the verification command is written as “without using sudo.” sudo may let one install write into a system directory, but it does not change the fact that the default prefix is not owned by your user. The next global install often hits the same error. - Do not
chmodorchownsystem directories such as/usr/localor/usr/lib, and do notchmod 777them, just to make a global install succeed. The official docs do not use that as a fix. - Do not treat this error as a broken npm and uninstall a Node installer first. The official install page recommends against installers, and says they can be a source of this global permissions problem. If you reinstall, prefer a version manager.
- Do not treat
listen EACCES, a container path such as/app/node_modules, or acommand not foundafter a successful install as the same problem.
Where this page stops
This page only covers npm install -g (or an equivalent global write) failing with EACCES because the current prefix is not writable. It does not pick a version manager for you, it does not promise that a non-interactive job, CI, or an AI agent will see the command after the prefix is fixed, and it does not cover the manual directory change on Windows. Trust the commands, prefixes, and config file names on your screen. Do not copy someone else’s username, prefix, or package name.
Other paths on the site start at Start Here. The Chinese writeup is npm ERR! code EACCES:先看全局前缀,再换目录或改用版本管理器.
If this post helps, you can sponsor the blog. This is voluntary personal support, not a charitable donation.