Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm install worked but the command is not found

Errorzsh: command not found: eslint

Short answer

npm puts a local install's command in the project's node_modules/.bin, which is not on your shell PATH, so run it with npx or from an npm script. A global install puts it in the prefix bin folder, which must be on your PATH. Check which kind of install you did.

  • Applies to npm 10, Node.js 22, zsh 5.9, macOS 15, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    See whether the command was installed in this project or globally.

    ls node_modules/.bin | head
    npm ls -g --depth=0
  2. 2Match what you see, then jump to its fix

    1. 1The name appears in node_modules/.bin but not in the global listIt was installed locally, and local commands are not on PATHFix
    2. 2npm ls -g lists the package, yet the shell cannot find the commandIt was installed globally but the global bin folder is not on PATHFix
    3. 3node_modules/.bin has the command in another project folder, or none hereThe install was run in a different folder from the one you are in nowFix

What does the error look like?

  • zsh: command not found: eslint
  • bash: vite: command not found
  • 'tsc' is not recognized as an internal or external command

Cause 1 of 3

It was installed locally, and local commands are not on PATH

1Check

A plain npm install links the command into ./node_modules/.bin of the project. npm scripts and npx see that folder, but your shell does not.

ls node_modules/.bin | grep eslint

2Fix

Run it through npx, or add it to the scripts of package.json and call it with npm run.

npx eslint .
# or in package.json: "scripts": { "lint": "eslint ." }
npm run lint

3Verify

The tool prints its output or version.

npx eslint --version

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 3

It was installed globally but the global bin folder is not on PATH

1Check

A global install links commands into the bin folder under the npm prefix on Unix. That folder must be listed in PATH.

npm config get prefix
echo "$PATH" | tr ':' '\n' | grep -n "$(npm config get prefix)"

2Fix

Add the bin folder to PATH in the profile file your shell reads. zsh reads ~/.zshrc, and the change applies only to new shells.

echo 'export PATH="$(npm config get prefix)/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

3Verify

The shell finds the command.

command -v eslint

Confirmed by docs.npmjs.com

Did this fix it?

Cause 3 of 3

The install was run in a different folder from the one you are in now

1Check

Local commands belong to one project. Moving to another folder, or running npm install above or below the project, leaves this folder without it.

pwd
ls package.json node_modules/.bin

2Fix

Change to the folder that holds the project and run the command there, or install the package in this project.

cd path/to/your-project
npm install --save-dev eslint

3Verify

npx finds the local copy.

npx eslint --version

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Prefer local installs plus npm scripts; each project then carries its own tool version.
  • Reserve global installs for tools you use outside any project.
  • Check npm config get prefix after changing Node.js version managers.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

npm or a script fails in WSL with /usr/bin/env: 'bash\r'

/usr/bin/env: 'bash\r': No such file or directory

The \r in the message is a Windows line ending at the end of a script's first line, so Linux looks for a program called bash followed by a carriage return.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.