nodejs

How To Fix zsh command not found npm

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:

Related Post

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:

npm –version
8.0.0

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

Recent Posts

What is the Purpose of php_eol in PHP?

in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More

2 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

2 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

2 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

3 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

3 months ago

Common Practices for Laravel Blade Template

in this Laravel tutorial, I will explore common practices for using the Laravel Blade template with examples. Blade is a… Read More

3 months ago

Categories