How to fix the 'npm command not found' error

Easy Steps On How you can fix “npm command not found” Error

Facebook
Twitter
LinkedIn
WhatsApp

If you are getting an “npm command not found” error and you want to resolve the problem. You have landed on the right page. When I downloaded this node package manager first time, I also got this error. You will get 100’s of solutions and commands on the internet, but I will give you specific commands.

I am sure that you will follow this post step by step. You can resolve the following errors. It doesn’t depend on which operating system you are using.

Solution 1 – How to fix npm command not found in Windows 10 operating system

 

If you don’t know the pre-requisite and right way to download npm. Then, you will definitely have this npm error situation. If you have already installed npm then skip to solutions 3, 4, or 5 based on what OS you have to fix your path or system variable.

Let me show you the right way of npm installation in windows.

 

How to install node on Windows 10

 

→ Step1: Download Node Js

 

Download Node.js software from this nodejs.org website. The most recent LTS version is node-v14.15.3. Package npm is in-built. You don’t have to install it separately. If you own an older version of windows, select the 32-bit version of the node.js installer. Else you can choose 64-bit in all other cases.

→ Step2- Install Node.js and npm

 

Double click on the installer node-v14.15.3-x64.msi and then follow the steps.

 

  • Step2.1 – Accept all the terms in the license agreement and click next.
  • Step2.2 – Select the folder for node.js installation. Default location of node.js is “C:\Program Files\nodejs\“. It will be better if you keep it default.
  • Step2.3 – Select node.js features. I will suggest you leave it by default. Make a note, npm (node package manager) will be there as part of this download. You don’t need to install it in a seperate way.
  • Step2.4 – Choose an optional tool (chocolatey) to compile native modules, if necessary. I can suggest you keep it unchecked.
  • Step2.5 – Click install.

→ Step 3 – Check the npm and node Js versions.


 

  1. Check the node js version.
  2. Then check npm (node package manager) version.
  3. Now you will not get any “npm command not found error” in Windows 10.

Solution 2 – How to fix npm command not found in Ubuntu OS

 

Let me tell you all the steps to get rid of these errors if you are a non-Windows user.

  1. sudo npm command not found.
  2. bash npm command not found.
  3. npm command not found ubuntu.

I have taken an example of Ubuntu 20.04 OS and let me show you the new installation process first.

How to install node JS and npm in Ubuntu 20.04 OS

 

  1. Step 1 Update the Ubuntu repository first.
  2. Step 2 Install Node JS First (Recommended)
    Run apt-get command to install node js package. Check out the suggested package in output, it says npm.
  3. Step 3 – Install npm (node package manager) in Ubuntu 20.04 OS.
  4. Step 4 At the end check npm and node js version.

Till this point, you must be okay. And further all issues related to “Bash or sudo: npm command not found” will go for sure.

Solution 3 – How to Fix npm command not found in Mac

 

In case you are facing the issue “npm command not found” in the mac OS. I will suggest you remove the existing installation and follow these steps to be successful.

  1. Step 1 – Delete node modules folder.
  2. Step 2 – Uninstall Node JS with the help of brew command.
  3. Step 3 – Install node with –without-npm option.
  4. Step 4 – Download npm package with the help of install script.
  5. Step 5 – Set environment variable in Bash.

This will solve all your npm-related errors in the mac operating system.

Solution 4 – Path or system variable changed resulting in npm error

 

Although, the paths are set by default when you install node js and npm in Windows and Ubuntu. But in these rare cases, it doesn’t occur. Or you can be messed up with it. Even in that case also get the npm command not found error.

Let’s see how to check and set up variables for npm in the case of Ubuntu 20.04

How you can check the npm path variable in Ubuntu 20.04

 

You need to make sure, that npm is already installed, if not, follow how to install node JS and npm in Ubuntu 20.04 steps in this article.

Step 1 Check a default path for npm command.

Step 2 – Check /etc/environment file for npm path.

Step 3 Edit /etc/environment file and add npm path.

Add npm path till bin folder at the end of environment file separated by a colon “:”. Then save and exit from file. Npm path should be within quotes ” “.

For example, /usr/bin in my case.

Reload environment file for changes.

How to check the npm path variable in Windows 10

 

First, you have to check whether node js and npm are installed in Windows 10 or not. If it’s already installed you need to follow these steps:-

 

  1. Step 1 – Search for the environment variable.
  2. Step 1.1 — Just type “environment variable” in the search area and click open.
  3. Step 1.2 – Click on the “Environment variables” in the advanced tab of System Properties.
  4. Step 1.3 – Select “Path” and then click on Edit.
  5. Step 1.4 – Check for npm path “C:\Program Files\node js”. It is a default target directory for Node.JS and npm.

If npm variable path doesn’t exist there, Click New > Add npm variable path “C:\Program Files\nodejs” > Click OK.

(Please take note that you need to replace the default “C:\Program Files\nodejs” with your custom target Folder. In case you have selected another different folder during the installation process.)

Click OK two times to close all open dialogue boxes.

Solution 5 – Permission issues on “node_modules”

If you are getting errors related to permissions, please run this command to give ownership to your user. It’s applicable only for Mac and Linux users.

For Mac users –

$ sudo chown -R $(whoami):admin /usr/local/lib/node_modules/

For Linux users –

$ sudo chown -R $(whoami):root /usr/local/lib/node_modules/

Solution 6 – Old Node version installed

 

If you are running an old version of npm already. You can update it to the most recent one by using the following command to resolve the npm command not found error.

Run this command, if you are running Ubuntu or Linux.

$ sudo npm install npm@latest -g

Check Node version

$ npm -v

For Windows users

Run the following commands in PowerShell one by one.

c:> Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force

c:> npm install -g npm-windows-upgrade

c:> npm-windows-upgrade

Check Node version

c:\> node —v

 

Most Common errors i.e Http Error 403. If you are facing an issue on your chrome browser, then you must checkout this blog on how to fix Http Error 403 | You Don’t have Authorization to View this Page (FIXED)

 

I hope, you would have been fixed your issue of the “npm not found error”. You can comment and let me know, which solution fixed your npm issue.

 

Frequently Asked Questions:-


1. What is the reason? NPM command isn’t working?

The reason could be that the npm package isn’t properly installed, or the path variable isn’t set to the npm package. Install npm and the node js package in the manner recommended, or configure the the npm path variable to solve the issue.

2. What exactly is NPM the Run command?

NPM run-script, also known as npm run (alias) can be described as the script used to execute any scripts for packages. npm run-script This is the language. Without , it will list the available scripts.

3. What is the purpose of the command npm install accomplish?

It is the NPM install command is used to install the package along with its dependencies. For additional assistance and help with syntax, type : npm install help.

4. What exactly is Test Command in NPM init?

If you’re developing a module using node.js using the init command. The npm test is a tool to aid you in test the running. It is crucial when integration with the CI/CD tools. If there are issues in the tests. The rollback process will be handled by your CI/CD. Actual deployment will not occur.

 

You May Also Like:-

1. How to Fix PR CONNECT RESET ERROR on Mozilla Firefox?
2. 0x80240fff: How To Fix This Windows 10 Update Error Code?
3. How To Fix Roblox Error Code 267?
4. How To Fix Video Playback Error Code: 22403 in Google Chrome?

Darshan Jain
Darshan Jain

Linkedin | Instagram

Hello Readers, Thank you spending out time in reading this blog. I' Darshan Jain writer of Digi Messiah. My hobbies is Coding and Writing, I am also a writer "Who write books :)"

Read My Post
Advertisement
Advertisement

You may also like:

Howtodownloadanimeepisodesonzoro.toandfunimationnow
How To Record, Edit And Share Videos In Camtasia Studio
Top 5 Best Websites For Stock Analysis
Digi Messiah