Home / Vibe Coding / zsh: command not found: npm on a Mac? Here’s the Real Fix

zsh: command not found: npm on a Mac? Here’s the Real Fix

zsh: command not found: npm before and after fixing PATH, real output from my zsh test

Vibe coding · Terminal basics · For beginners

zsh: command not found: npm on a Mac? Here’s the Real Fix

Your Mac isn’t broken. Your terminal just doesn’t know where npm lives.

Three quick checks, three fixes, and the two mistakes that make “I already fixed it” still fail — each one reproduced in a real test terminal.

You know the feeling. Your AI assistant hands you a neat little plan: “Open Terminal and run npm install.” You find Terminal, paste the line, press Enter — and get one cold sentence back: zsh: command not found: npm.

No explanation. No next step. And the AI that told you to run it often assumes npm is already there. This error is not about your code — your project hasn’t even started yet. It’s about your terminal not being able to find a program. Once you see it that way, the fix is usually one of three things.

The short version

“zsh: command not found: npm” means your terminal searched its list of program folders (called PATH) and found no npm. Either Node.js isn’t installed (npm comes with it), it’s installed in a folder your PATH doesn’t include, or you edited your settings but haven’t opened a new terminal window yet.

How I tested this. On Nov 13, 2026 I reproduced each situation below in zsh 5.9 (the same shell a Mac uses) inside a clean Linux test account, with Node v22.23.4 and the nvm v0.41.0 installer. Every error message in this post is copied from those runs.

What I did not do. I didn’t run this on a physical Mac, and my test machine couldn’t reach nodejs.org, so I couldn’t finish an nvm install download. Mac-specific facts (default shell, Homebrew’s folder) come from Apple’s, Homebrew’s and nvm’s own docs, linked where I use them.

What “zsh: command not found: npm” actually means

Two words in that sentence need translating. zsh is the program behind your Terminal window — the thing that reads what you type. Apple says zsh is the default shell for all newly created user accounts starting with macOS 10.15 (Apple Support), which is why your error starts with “zsh:” and not “bash:”.

PATH is a list of folders. When you type npm, zsh walks through those folders one by one, looking for a file called npm. If it reaches the end of the list empty-handed, you get the error. That’s all it is.

Here’s the part that surprised me most in testing. I put a working copy of npm in a folder that wasn’t on the list, and zsh still said it didn’t exist — even though ls showed the file sitting right there:

% npm -v
zsh: command not found: npm

% ls ~/tools/node/bin/npm
/Users/you/tools/node/bin/npm     <- the file is right there

“Not found” means “not in the folders I check,” not “not on your computer.” Keep that in mind and every fix below makes sense.

(If your error has more than one line, or mentions a file instead of a command, it’s a different problem — how to read error messages when you can’t code walks through those.)

The 30-second check: which problem do you have?

Paste these one at a time. They only read information; they don’t change anything on your Mac.

node -v
npm -v
echo $PATH
ls /opt/homebrew/bin/npm /usr/local/bin/npm ~/.nvm

The first two are the version checks npm’s own docs recommend (npm Docs). The last line peeks into the usual places npm ends up. Now match what you see:

What you seeWhat it meansGo to
node and npm both “not found,” and the ls line finds nothingNode.js was never installedFix 1
~/.nvm exists, but nvm is also “not found”nvm is installed but never switched onFix 2
ls finds npm, but its folder isn’t in your echo $PATH outputInstalled, but PATH doesn’t include itFix 3
You already added it to PATH and it still failsOld window, or wrong settings file“It still doesn’t work” section
Flowchart: three terminal checks that tell you which fix you need for zsh: command not found: npm
Chart: MindWiredAI. Data source: my own zsh 5.9 test runs, Nov 13, 2026, plus npm Docs, Downloading and installing Node.js and npm — version-check commands.

Fix 1: npm isn’t installed — install Node.js

npm isn’t a separate app you download. It comes bundled with Node.js. So if node -v is also “not found,” you don’t have an npm problem — you have a “nothing installed yet” problem, and that’s the easiest one to fix.

You have two common routes. The official installer from nodejs.org is the click-through option. npm’s own docs, though, take a clear side: “We strongly recommend using a Node version manager like nvm,” and they warn that Node installers can cause permission errors when you install packages globally (npm Docs).

My recommendation for vibe coders: go with nvm, because the people who make npm say so — but know that it has two traps of its own, which is exactly what Fix 2 covers. If you’d rather avoid the terminal entirely for now, the installer works too; just remember you chose it if permission errors show up later.

⚠️ Before you paste an install command

Install commands for nvm and Homebrew download a script from the internet and run it. Copy them only from the official page (nvm’s GitHub README, brew.sh) — not from a random blog, and not from an AI chat without checking the address matches the official one. And don’t “fix” npm errors with sudo unless you know why; it’s a common cause of the permission mess npm’s docs warn about.

Fix 2: “nvm: command not found” right after installing nvm

This is the trap most beginners hit, and it’s not your fault. The nvm installer tries to write two lines into a hidden settings file in your home folder. On a fresh Mac, that file often doesn’t exist. nvm’s README says it plainly: since macOS 10.15 the default shell is zsh, nvm looks for .zshrc to update, and “none is installed by default” (nvm README, Troubleshooting on macOS).

I ran the official installer in a test account with no settings files. It did download nvm — and then printed this, which is very easy to scroll past:

=> Profile not found. Tried ~/.bashrc, ~/.bash_profile,
   ~/.zprofile, ~/.zshrc, and ~/.profile.
=> Create one of them and run this script again

# then, in a brand-new terminal window:
% nvm --version
zsh: command not found: nvm

The fix is the one nvm’s README gives: create the file, then run the install command again.

touch ~/.zshrc
# now re-run the install line from nvm's README, then
# close Terminal and open a new window

On my second run the installer reported it was appending its lines to .zshrc, and a new window answered nvm --version with 0.41.0.

The second trap: nvm works, npm still doesn’t

This one caught me in the same test. With nvm finally working, I typed npm -v — and got zsh: command not found: npm again. nvm is only the installer. Installing nvm does not install Node. You still have to ask it to:

nvm install --lts
node -v
npm -v

--lts means the long-term-support version, the stable one. (My test machine was blocked from nodejs.org, so this download is the one step I couldn’t complete myself; the command is the documented one.)

Fix 3: Node is installed, but npm isn’t on your PATH

If the ls line from the 30-second check found npm somewhere, the program exists — your PATH just doesn’t list its folder. Which folder depends on how you installed it:

Homebrew on an Apple Silicon Mac: /opt/homebrew/bin. Homebrew’s docs give that as the default folder and note that the installer prints shell setup directions — “If you don’t follow those directions, Homebrew will not work” (Homebrew Docs). The line it asks for looks like eval "$(/opt/homebrew/bin/brew shellenv)".

nvm: inside ~/.nvm. You don’t edit PATH by hand here — the two nvm lines in .zshrc do it. If they’re missing, go back to Fix 2.

The nodejs.org installer: commonly /usr/local/bin. I couldn’t confirm this on the current installer page, so trust what your ls line actually shows.

To add a folder yourself, append one line to .zshrc. Replace the folder with the one your ls found:

echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc

Two details matter. Use two arrows, >> — that adds a line at the end. A single > replaces the whole file, wiping anything nvm or Homebrew put there. And keep :$PATH at the end, or you’ll replace your folder list instead of adding to it.

One more thing I learned the hard way in testing: you can’t dodge PATH by typing npm’s full address. When I ran npm by its full path, it failed with /usr/bin/env: 'node': No such file or directory. npm needs to find node on your PATH too — so fix the PATH, don’t work around it.

“I actually added it to PATH and it still doesn’t work”

This is the most frustrating version, because you did the fix. In my tests, it came down to one of two things.

1. You’re still in the same terminal window

zsh reads .zshrc when a window opens — not while you’re using it. In my test, I added the PATH line and ran npm -v in the same window: still “command not found.” Then I ran source ~/.zshrc (which says “re-read the file now”) and the very next npm -v printed 10.9.9. A brand-new window worked straight away too.

% echo 'export PATH="$HOME/tools/node/bin:$PATH"' >> ~/.zshrc
% npm -v
zsh: command not found: npm      <- same window, old settings
% source ~/.zshrc
% npm -v
10.9.9

So: after any change to .zshrc, open a new Terminal window before you decide it didn’t work. No need to restart the Mac.

2. You put the line in a bash file

Lots of older tutorials (and some AI answers) say to edit ~/.bash_profile. That file belongs to bash, the shell Macs used before zsh. I put the exact same PATH line in .bash_profile: bash found npm, zsh still said “command not found.” zsh’s manual lists the files it reads — .zshenv, .zprofile, .zshrc, .zlogin — and bash’s files aren’t among them (zsh manual, Startup Files).

Real zsh test results: eight setups and whether npm was found, from missing Node to PATH line in the wrong file
Chart: MindWiredAI. Data source: my own test runs in zsh 5.9, Nov 13, 2026; file rules from zsh manual, Startup/Shutdown Files — order of startup files.

On Windows instead? “npm is not recognized”

Windows says the same thing in different words: 'npm' is not recognized as an internal or external command. The idea is identical — Windows has its own PATH list — but the fix lives in a settings screen, not a hidden file. Start with how environment variables work on Windows, and as on a Mac, close and reopen your terminal after changing anything. I didn’t test Windows for this post.

npm works now. What’s the next error you’ll probably see?

Honestly, most people’s very next stop is this one. Once npm was found, I ran npm install in an empty folder:

npm error code ENOENT
npm error enoent Could not read package.json: Error: ENOENT:
  no such file or directory, open '.../Desktop/empty/package.json'

That’s good news in disguise: npm is installed and running. It just means you’re standing in the wrong folder. Use cd to move into your project folder (the one with package.json in it) and try again. If something breaks after that, here’s how to undo it when AI broke your working code.

💡 Tell your AI what you saw

When you paste this error into Claude, ChatGPT or Cursor, include the output of node -v, echo $PATH and how you installed Node. Without those, AI tends to suggest reinstalling everything. With them, it can usually point at the one missing line.

The honest limitations

I reproduced every error here in zsh, but on a Linux test account, not a physical Mac. The behavior of PATH and .zshrc is the same shell logic, yet Mac-only details — Apple’s default settings, Homebrew’s folder, where the nodejs.org installer puts files — come from documentation, not my own machine. I couldn’t download Node through nvm because my test environment blocked nodejs.org. And I didn’t test Windows, code editors’ built-in terminals, or Macs managed by a company IT team, which can have extra rules.

Who should actually care

Worth it if: you’re building your first app with AI and the instructions keep saying “run npm” — this is a one-time fix, and every JavaScript tutorial after it assumes you’ve done it.

Maybe not if: you build only inside browser tools like Lovable, Bolt or Replit. They handle npm for you behind the scenes, so you may never need it on your own Mac.

Skip if: your company manages your Mac. Ask IT first — installers and PATH changes may be blocked or against policy.

FAQ

Do I need to restart my Mac after fixing PATH?

No. Close the Terminal window and open a new one, or run source ~/.zshrc. In my test, either one picked up the change immediately.

Is it safe to edit .zshrc?

Yes, if you add lines rather than replace the file. Use >>, never a single >. If something goes wrong, the file is plain text — you can open it with open -e ~/.zshrc and delete the last line you added.

Should I use sudo to fix npm?

Not for this error. sudo doesn’t help zsh find a program that isn’t on PATH, and npm’s docs point to a version manager like nvm as the way to avoid global permission errors.

What’s the difference between .zshrc and .zprofile?

Both are zsh settings files. According to zsh’s manual, .zprofile is read by login shells and .zshrc by interactive shells. For a beginner adding one PATH line, .zshrc is the usual place; Homebrew may ask for .zprofile — follow what its installer prints.

The bottom line

“zsh: command not found: npm” is a map problem, not a broken computer. Either Node isn’t installed, it’s installed somewhere your terminal doesn’t look, or you haven’t opened a fresh window since you fixed it. Three checks tell you which one, and each fix is a single line.

Your next step: open a new Terminal window right now and run node -v. Whatever it says tells you which section above is yours.

Explore MindWiredAI →

Related free AI guides

Published Nov 13, 2026. Tested in zsh 5.9 with Node v22.23.4 and the nvm v0.41.0 installer.

Tagged:

Leave a Reply

Your email address will not be published. Required fields are marked *

🔥 Don't miss the latest from AI Agent News! Subscribe Now 👉