How To Fix zsh command not found npm — Phpflow.com

This node tutorial help to solve "zsh:command not found:npm" error, We'll replicate the issue and solve the issue using npm.

Sometimes, I have installed nodejs and try to run npm commands such as npm install, the Terminal would respond with npm command not found error as shown below:

$ npm install -g n 
zsh: command not found: npm

The error occurs when your computer can’t find the PATH environment variable in your computer.

What is the PATH variable?

The PATH variable must include the address of any new program on your computer that you want to start through the command-line interface.

When you execute the npm command from the window Terminal, your computer will look through all the folders listed under PATH to find the npm executable file and pass your commands to it.

if the npm executable file is not found, then your computer will respond with the command not found error below:

zsh: command not found: npm

How To check PATh variables in Windows

You can run the below command into your windows terminal to show all windows PATH variables.

echo %Path%

However, if I write in terminal npm is says “zsh: command not found: npm”

How to set Path Variables

We can set a new or edit system variable as follows:

Step 1: Open the search menu and typing “environment”, and pressing open.

The search panel shows up on the screen. You can observe two types of variables:

User Variables: Use them when you wish to change the environment variables for the current or specific user.
System Variables: Use them when you want the system-wide changes.

Step 2:

I want to change the path variable system-wide, hence I will click on “Edit the system variable”.

Step 3:

The system variable modal window will open, Now I’ll click “Environment Variables…”.

Step 4:

Let’s select PATH variable as like the hightlighter row in the below image, click on “Edit” button.

Step 5:

Click the New button to add new paths or edit to modify the existing path. Delete will delete a path. At the end of the variable values, add C:\Program Files\nodejs as a new entry to your Path variable:

Press “OK” to save the changes.

Windows PATH environment variable using the Command Prompt

You can add the location to the Windows PATH environment variable using the Command Prompt as follows:

SET PATH=C:\Program Files\nodejs;%PATH%

The npm -version command should allow you to confirm that the npm command not found error has been resolved:

If the problem continues, try first restarting your computer. After you restart, the error should be fixed.

Originally published at https://www.phpflow.com on October 3, 2022.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Parvez Alam

Hey, I am Parvez Alam. A software developer since 2009. I love learning and sharing knowledge. https://www.phpflow.com/