Bash npm command not found windows

If you are getting "npm command not found" error on any OS. Follow step by step solutions in this post and npm issue will vanish, i bet

This post is for all javascript newbies. If you are getting an «npm command not found» error and want to resolve it. You have landed on the right page. When I installed this node package manager first time, I also got this error. You will get hundreds of solutions and commands on the internet, but I will give you bullseye commands.

I am sure if you will follow this post step by step. You will be able to resolve the following errors. Doesn’t matter which platform or operating system you are using.

You may also find similar errors related to npm as follows-

  • sudo npm command not found
  • mac npm command not found
  • bash npm command not found
  • npm command not found windows
  • npm command not found ubuntu
  • npm install not working

This issue may occur when you have recently installed or upgraded npm (node package manager) and node js.

Possible Causes —

  1. npm is not correctly installed
  2. Node js is not installed
  3. Path or system variable changed
  4. Permission issues
  5. The old node version installed
  6. No package.json file describing the dependencies
  7. Integrity check failed error

Articles on troubleshooting, you may find useful —

  • Yarn command not found error
  • Sudo command not found error
  • Fix «mkvirtualenv command not found» error
  • Nodemon command not found
  • Nodemon app crashed — Waiting for file changes before starting
  • Keytool command issues
  • Cmake command errors

Table of Contents

  • 1 Solution 1 — How to fix npm command not found in Windows 10
  • 2 Solution 2 — How to fix npm command not found in Ubuntu
  • 3 Solution 3 — How to Fix npm command not found — Mac
  • 4 Solution 4 — Path or system variable changed resulting in npm error
  • 5 Solution 5 — Permission issues on «node_modules»
  • 6 Solution 6 — Old Node version installed
  • 7 Solution 7 — No package.Json file issue
  • 8 Solution 8 — Integrity check failed
  • 9 FAQs:- NPM command not found
  • 10 Conclusion

Solution 1 — How to fix npm command not found in Windows 10

If you don’t know the pre-requisite and correct way of npm installation. Then, you will definitely land into this npm error situation. If you have npm already installed 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 correct way of npm installation in windows.

How to install node js on Windows 10

Watch out for this video tutorial to know how to install Node JS and NPM correctly in windows 10. If you want to check out the step-by-step tutorial, keep reading.

Step1 — Download Node Js

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

Download-node-js

Step2— Install Node.js and npm

Double click installer node-v14.15.3-x64.msi and follow the installation wizard.

Step2.1Accept the terms in the license agreement and click next.

node-js-EULA

Step2.2 — Select the destination folder for node.js installation. Default location of node.js is «C:Program Filesnodejs«. I will recommend keeping it default.

node-js-installation-folder

Step2.3 — Select node.js features. I will suggest you leave it as default. Make a note, that npm (node package manager) will be there as part of this installation. You don’t need to install it separately.

select-npm-to-fix-npm-command-not-found

Step2.4 — Choose an optional tool (chocolatey) to compile native modules, if required. I will suggest you, keep it unchecked.

node-js-dependent-native-modules

Step2.5 — Click install, Sit back and relax. it will take a few minutes.

Fix-npm-command-not-found-windows10validating-node-js-and-npm-install

Step 3 — Check npm and node Js version.

Check node js version

C:> node -v 

Check npm (node package manager) version

C:> npm -v

check-node-js-version

Now you will not get any «npm command not found error» in Windows.

Detailed step-by-step guide on, how to install Node JS and npm using PowerShell (Chocolatey) tool.

Solution 2 — How to fix npm command not found in Ubuntu

So we have already seen, how to resolve the npm command not found error in Windows 10 but what about non-windows users. Let me tell you 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 first I will show you the new installation process.

Watch out for this video tutorial for Node js and npm installation in Ubuntu 20.04. In this video, I have shown, more than one way to install it.

  • Using Ubuntu repository
  • Using Node Source repository

If you like reading, instead of watching videos. Keep reading further.

How to install node JS and npm in Ubuntu 20.04

Step1 — Update the Ubuntu repository first

$ sudo apt-get update

apt-get-update

Step2 — Install Node JS First (Recommended)

Run apt-get command to install nodejs package. Check out the suggested package in output, it says npm.

$ sudo apt-get install nodejs

Install-nodejs-using-apt

Step3 — Install npm (node package manager) in Ubuntu 20.04

Sometimes you scratch your head, Why npm command not found error, even after installing the node? Because in Windows, npm is installed with node Js. But in the case of Ubuntu, you need to install it separately.

Now let’s install node package manager (npm) which is required by Node Js. If you will not install this, you will end up with «npm» error.

$ sudo apt-get install npm

Fix-npm-command-not-found-ubuntu

Step4 — Check npm and node js version

Check npm version

$ sudo npm -v 

check-npm-version

Check node version

$ node -v

check-node-js-version

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

If you are interested in the latest version of npm and node js installation. Checkout out this tutorial on node js and npm using the NodeSource repository

Solution 3 — How to Fix npm command not found — Mac

In case you are facing the issue «npm command not found» in the mac operating system. I will recommend you remove the existing installation and follow these steps to be successful.

Step1 — Remove the node_modules folder

 > rm -rf /usr/local/lib/node_modules

Step2 — Uninstall Node JS using the brew command

> brew uninstall node

Step3 — Install node with —without-npm option.

> brew install node --without-npm

###Then####

> echo prefix=~/.npm-packages >> ~/.npmrc

Step4 — Install the npm package using the install script

> curl -L https://www.npmjs.com/install.sh | sh

Step5 — Set environment variable in Bash

> export PATH="$HOME/.npm-packages/bin:$PATH"
> export PATH="$HOME/.node/bin:$PATH"

This will resolve all your npm-related errors in mac OS. Watch out for the official nodesource installation guide for further reference.

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

Although, Path and variables are set by default when you install node js and npm in Windows and Ubuntu. But in rare cases, it doesn’t happen. Or maybe you messed up with it. Even in that case, you will 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 to check the npm path variable in Ubuntu 20.04

First, you need to make sure, npm is installed, if not, follow the How to install node JS and npm in Ubuntu 20.04 steps in this post.

Step1 — Check the default path for the npm command

$ which npm

Check-npm-path

Step2 — Check /etc/environment file for npm path

Now we need to check, do we have /usr/bin/npm or your npm command path in /etc/environment file.

$ cat /etc/environment

set-npm-path-variable-fix-npm-command-not-found

As you will see, /usr/bin is already part of my environment variable. So I will not get this error. In case you don’t have your npm path in this file, add it.

Step3 — Edit /etc/environment file and add npm path

$ vi /etc/environment

Add npm path till bin folder at the end of environment file separated by a colon «:». Save and exit from file. Make a note, npm path should be within quotes » «.

For example, /usr/bin in my case.

Reload the environment file for changes.

$ source /etc/environment

How to check the npm path variable in Windows 10

First, you need to make sure, node js and npm are installed in Windows 10. If it’s already there, you need to follow these steps

Step1 — Search for environment variable

Step1.1 — Type «environment variable» in the search box and click open.

open-environment-variable-windows10

Step1.2 — Click on «Environment variables» in the Advanced tab of System Properties.

Fix-variable-npm-command-not-found

Step1.3 — Select «Path» and then click Edit.

Edit-environment-variable-npm-command-not-found

Step1.4 — Check for npm path «C:Program Filesnodejs«. It is the default target directory for Node.JS and npm.

If npm variable path doesn’t exist, Click New > Add npm variable path «C:Program Filesnodejs» > Click OK.

Please make a note, that you need to replace the default «C:Program Filesnodejs» with your custom target Folder. In case you have selected a different folder during installation.

add-variable-to-solve-npm-command-not-found

Click OK twice to close all open dialogue boxes.

Solution 5 — Permission issues on «node_modules«

if you are getting permission-related errors, please run this command to give ownership to your user. It’s applicable to 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/

Make sure you provide the correct path for node_modules.

Solution 6 — Old Node version installed

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

Run this command, if you are running Ubuntu Linux

$ sudo npm install npm@latest -g

Check Node version

$ npm -v

For Windows users

Run the below-mentioned 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

Solution 7 — No package.Json file issue

If you run the npm install command and then make sure you have package.json file existing in the same directory. Else you will encounter npm install errors.

  • Run ls -l command to check whether the package.json file exists or not.
$ ls -1
index.js
package-lock.json
package.json
  • Then run npm install command and recommendation are to run it always from the root folder. The npm install command by default install all the packages under the dependencies object of your package.json file.

For example —

{
"name": "sample-app",
"version": "2.0.1",
"description": "A Node app",
"dependencies": {
"jest": "^28.1.1",
"typescript": "^4.5.5",
}
}

In this example, the npm install the command will install jest and typescript packages to the generated node_modules folder as it’s mentioned in the package.json file.

Solution 8 — Integrity check failed

If you have a package.json file under your project directory, and you are trying to run the npm install command. The npm will compare the integrity of the package you downloaded with the one specified in the package-lock.json file. In cases it differs, it will throw an error integrity failed check error.

npm ERR! Verification failed while extracting @my-package@^1.3.0:
npm ERR! Verification failed while extracting @my-package@^1.3.0:
npm ERR! Integrity check failed:

To solve this error, you need to move or delete your lock file and clean the npm cache. Follow these steps from your project’s root directory.

  • Remove or move your package-lock.json file.
$ sudo rm package-lock.json
or
$ sudo mv package-lock.json /tmp
  • Move or delete the node-modules folder. You can also delete it but I will recommend it to move them to a different or /tmp directory to roll back changes, in case required.
$ sudo mv node_modules /tmp

# in case you want to delete

$ sudo rm -rf node_modules
  • Forcefully clear the npm cache
$ npm cache clean --force

Then run the npm install command again. It should fix your integrity issue.

  1. Why NPM command is not working?

    The reason may be either the npm package is not installed, incorrectly installed or the path variable is not set for npm. Install npm and node js package as recommended or set up the npm path variable to resolve it.

  2. What is the NPM Run command?

    npm run-script or npm run (alias) is the command to execute arbitrary package scripts. npm run-script <command> is the syntax. Without <command>, it will list the available scripts.

  3. What does the command npm install do?

    The npm install command helps to install a package and its dependencies. For further help and syntax run: npm install help

  4. Is not recognized as an internal or external command NPM?

    This means the npm command is not recognized. Make sure you install node js software. NPM will automatically install with node.js in the case of Windows. For non-windows users (Linux or Mac), Install node js first and then the npm package individually.

  5. What is Test Command in NPM init?

    If you are creating a module in node.js using the npm init command. The npm test will help you test the run. It is important while integrating with CI/CD tools. If there are problems with tests. Rollback will be done by your CI/CD and actual deployment will not happen.

  6. How do I know if npm is installed?

    Run the npm -v command on the terminal or command prompt, to check whether npm is installed or not. In case you get «npm command not found error». Either npm is not installed or your path variable is not set up correctly.

Conclusion

Based on the error, follow the required solution from the post. I hope, by this time, you would have fixed your issue of the «npm not found error«. Please comment and let me know, which solution fixed your npm issue.

Please share it on your social media page, so that it can be helpful for others also.

I’m learning laravel and follwing this tutorial,

But when I went try and install npm, is says bash: npm: command not found

enter image description here

Henke's user avatar

Henke

3,6813 gold badges25 silver badges36 bronze badges

asked Aug 9, 2017 at 8:07

Deo's user avatar

4

If you have already installed nodejs and still getting this error. npm: command not found..

run this

apt-get install -y npm

answered Feb 6, 2019 at 8:41

Black Mask's user avatar

Black MaskBlack Mask

2933 silver badges3 bronze badges

3

I also come here for the same problem, The solution I found is to install npm and then restart the Visual Studio Code

answered Jun 6, 2019 at 3:23

Naimur Hasan's user avatar

1

in redhat base OS (tested in centos 7)

yum install nodejs npm -y

in debian base OS

apt-get install -y npm    

answered Feb 2, 2019 at 14:37

Omid Ahmadyani's user avatar

1

I am following the same tuturial and I had this issue and how I solved is just download the

8.11.4 LTS version

from this link then install it then the command worked just fine!

Community's user avatar

answered Aug 28, 2018 at 13:06

Ibrahim Max Alyousfi's user avatar

3

I know it’s an old question. But it keeps showing in google first position and all it says it’s «install node.js».
For a newbie this is not obvious, so all you have to do is go to the node.js website and search for the command for your linux distribution version or any other operating system. Here is the link:
https://nodejs.org/en/download/package-manager/

In this page you have to choose your operating system and you’ll find your command. Then you just log into your console as a root (using putty for instance) and execute that command.

After that, you log as normal user and go again inside your laravel application folder and run again npm install command, and it should work.
Hope it helps.

answered Jul 19, 2018 at 7:27

gallo2000sv's user avatar

gallo2000svgallo2000sv

1111 gold badge2 silver badges12 bronze badges

1

The solution is simple.

After installing Node, you should restart your VScode and run npm install command.

answered May 13, 2020 at 10:55

Voontent's user avatar

VoontentVoontent

6795 silver badges7 bronze badges

0

If you already installed npm globally on your system, and you are still getting the above error message by using VSCode terminal. Just close your VSCode application and reopen again, that should resolve the issue.

answered May 28, 2020 at 16:10

an-apluss's user avatar

an-aplussan-apluss

3653 silver badges9 bronze badges

First You need to check the node version using terminal (not gitbash)

node --version

npm --version

if those exists, Restart your pc and check

Cheers !!

answered Mar 18, 2022 at 10:16

janadari ekanayaka's user avatar

In my case it was entirely my fault (as usual) I was changing the system path under the environment variables, in Windows, and messed up the path for Node/NPM. So the solution is to either re-add the path for NPM, see this answer
or the lazy option: re-install it which will re-add it for you.

answered Jun 9, 2019 at 13:11

Mirza Sisic's user avatar

Mirza SisicMirza Sisic

2,3554 gold badges26 silver badges36 bronze badges

JavaScript and npm are two powerful tools that work together to help you build websites and applications. JavaScript is a programming language that runs in your web browser, and npm is a package manager that helps you install and manage software packages.

One of the many errors that confuses JavaScript beginners is the “npm: command not found” error, which happens when you try to run npm commands such as npm install.

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

In this article, we will show you a few solutions to fix “npm: command not found” in major platforms such as Windows, macOS and Linux. The fix may vary between different operating system and configurations, but the principles remain the same.

There are several things that can trigger the ‘npm command not found’ error:

  • npm is not installed: If you’ve downloaded Node.js installer from the official website, npm should be installed already with Node.js. But in order to have a proper setup, follow the advice from npm documentation : We strongly recommend using a Node version manager like nvm to install Node.js and npm. We do not recommend using a Node installer, since the Node installation process installs npm in a directory with local permissions and can cause permissions errors when you run npm packages globally.
  • npm is not present in PATH system variable: Most operating systems look for executables and binaries in a specific set of places. The list of all those places is stored in an environment variable, often named PATH.
  • Node.js is outdated while npm is up-to-date: One software package that depends on another expects its companion to be in a specific version.
  • The current user does not have permission to call npm binary

How to fix “npm command not found” error on Windows

Verify Node.js and npm installation

Before going any further and trying any other solutions, make sure you have Node.js and npm already installed. In order to do so, first, open an elevated PowerShell windows by right-clicking on the Windows icon on the taskbar. and select Windows PowerShell (Admin).

windows powershell admin

Then, sequenrially run “node -v” and “npm -v” to print out Node.js and npm version number. If both commands returned, then Node.js and npm are already installed on your system. Otherwise, you have to download the installer from https://nodejs.org/en/download/ and run it with administrator rights.

Check PATH system variable for Node.js path

If you have Node.js and npm installed, yet the “npm: command not found” persists, the path where npm binary is placed in may not be added to PATH.

Press Start key on your keyboard or click Start button and search for Edit the system environment variables.

edit the system environment variables

In the System Properties window , switch to Advanced tab and select Environment Variables…

system properties

In the Environment Variables window, under System variables, look for Path or PATH system variable, then select Edit….

environment variables

In the list, look for C:Program Filesnodejs. If it’s not presented in the list, to add the path aforementioned to the PATH system variable

Adding the Node executable folder location to Path variable

Update Node.js

Make sure you’re using the latest version of Node.js to avoid any serious issues. Upgrading is easy – just follow these simple steps.

  1. Right-click on the Windows icon on the taskbar. Select Windows PowerShell (Admin).
  2. Run the following commands to update Node.js and npm:
    • Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    • npm install -g npm-windows-upgrade
    • npm-windows-upgrade
  3. After any packages install and update, check your version of Node.js to ensure it’s updated by entering “node -v“.

Fix “npm command not found” error in Linux

There are many Linux distributions available, but for the sake of simplicity, this article will focus on solutions for Ubuntu. Ubuntu is one of the most popular Linux distributions and has been around since 2004. It is the perfect choice for those looking for a user-friendly option. You can adapt the instructions below to other Linux distribution as well, including Linux Mint, Fedora, RHEL, etc.

Reinstall npm

If you’ve have already installed nodejs and npm, yet still getting “npm: command not found”, you can try reinstalling it once again by running these commands against a terminal window.

sudo apt-get purge npm node sudo apt-get install npm node -y

Code language: JavaScript (javascript)

Reload or restart VSCode

If you’ve installed npm globally on your system, and you’re getting the error message from VSCode terminal, it might be the terminal that didn’t update the VSCode application. Just close all VSCode windows and reopen the application again to reload all of its module – that should be enough to resolve the issue.

Add npm to PATH system variable

Just like Windows, Linux uses the PATH environment variable to find binaries for each command that run against the terminal. Follow these instructions to add npm to PATH :

  • Open a terminal window pressing CTRL+ALT+T keyboard combination
  • Run which npm to locate the path where npm is placed. You’ll get something like /usr/bin/npm
  • Now run export PATH="/usr/bin:$PATH" to add npm binary location to PATH system variable.
  • You may have to restart the computer for the changes to take effect.

Install Nodejs and npm using nvm

To install or update nvm, you should run its install script. To do that, you may either download and run the script manually, or use the following cURL or Wget command. Please note that the command is ran

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash # OR wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Code language: PHP (php)

Running either of the above commands downloads the nvm installation script and runs it. The script essentially clones the nvm repository to ~/.nvm, and attempts to add the source lines from the snippet below to the correct profile file (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

Code language: PHP (php)

At this point, you may need to log out of your account or reboot the computer for the changes to take effect. Once nvm is installed, you can install the current LTS (Long Term Support) version of Node.js and npm with the following command :

nvm install --lts

The output may look something like this.

Installing latest LTS version. Downloading and installing node v10.16.3... Downloading https://nodejs.org/dist/v10.16.3/node-v10.16.3-darwin-x64.tar.xz... ######################################################################## 100.0% Computing checksum with sha256sum Checksums matched! Now using node v10.16.3 (npm v6.9.0) Creating default alias: default -> lts/* (-> v10.16.3)

Code language: PHP (php)

Give the current user permission to npm path

In rare cases, npm: command not found can be the result of users not having the permission to read and execute the binary. You can easily verify this by prefixing any command with sudo to run it with root privileges. For example, sudo npm --v.

This is often the case with Linux and macOS users. In order to fix any permission

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

Code language: JavaScript (javascript)

The command recursively give the current user the permissions to /usr/local/lib/node_modules/, which is where your node packages are placed. After running the above command,  try the npm command you were attempting again.

Fix “npm command not found” error in macOS

Homebrew is a free and open-source software package management system for Apple’s macOS and Linux operating systems, allowing users to easily install software.

While not being pre-installed on every macOS device, it’s a third-party package manager that administrators never knew they needed until they tried it out

The lightweight package manager is based on Ruby and uses GitHub to fetch installs, update apps, and add repositories where developers can add applications to be managed through command-line interfaces.

Currently, this is by far the easiest way you can get Node.js and npm installed on your macOS-based computer.

In order to install Homebrew, carefully copy and paste the one-line installation command and paste it into Terminal.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Code language: JavaScript (javascript)

If you’re wondering why the command includes /bin/bash instead of ruby like usual, the answer is Homebrew installer has been rewritten in Bash recently to ensure better compatibility.

The Homebrew installer does automatically add brew to PATH, but sometimes, the process may have been interrupted. In that case, you may want to check out our guide on how to fix “brew: command not found” error.

Conclusion

The “npm command not found” error can be a real pain when you’re working to develop an application and need access to an important directory like npm. Without npm, you don’t have access to the libraries for Node.js, which can significantly increase the time it takes to code common features.

If you likes to code in JavaScript, you may be interested in our post on JSON’s end of file expected, which is a very common error that confuses beginners.

When you try to run npm commands such as npm install, there may be times when the Terminal would respond with npm command not found error as shown below:

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

The command not found error occurs when your computer can’t find the associated program on your computer’s PATH environment variable.

The PATH environment variable is a list of directories specifying where your computer should look for a program to run from the Terminal.

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

When the npm executable file is not found, then your computer will respond with the command not found error above.

When you install or update your npm version, the folder where the npm executable file should be automatically added to your computer’s PATH environment variable.

The reason why your npm command can’t be found might be that the PATH environment variable is somehow misconfigured.

To fix this error, you need to add the folder where the npm executable file is located back to the PATH variable.

But to do this, you need to know where your npm executable file is located first.

For Windows users, the npm executable file may be located inside C:Program Filesnodejs

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

> SET PATH=C:Program Filesnodejs;%PATH%
> npm

Or you can set the PATH variable by using Windows graphical UI.

The following steps will help you to fix the error from the Windows interface.

Fixing npm command not found error on Windows OS

First, Go to My Computer or This PC for Windows 10. Right-click on empty space and open the Properties window:

Click Advanced system settings from the left bar of the Properties window:

Now you’re in the System Properties window. Click the Environment Variables... button:

Now you’re in the Environment Variables window. Select the Path variable from either the User Variables or System Variables table and click on the Edit... button:

At the end of the variable values, add C:Program Filesnodejs as a new entry to your Path variable:

If you installed NodeJS on another location, then you need to change the entry to your custom location. Remember to always enter the absolute path from the drive letter to your NodeJS program folder.

Once done, click OK and open a new Terminal or Command Line window. If you’re calling npm from the VSCode terminal, you need to restart VSCode first before trying again.

The npm command not found error should be fixed and you should be able to check this using the npm --version command:

If you still get the error, then try restarting your computer first. The error should be gone after you restart.

Now you’ve learned how to fix the error on Windows, it’s time to fix the error on macOS or Linux system.

Fix npm command not found error on macOS or Linux

The npm executable file is usually installed under /usr/local/bin/ for macOS and Linux systems, so you need to see if the location is already added to your PATH variable using the echo command as shown below:

$ echo $PATH
:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

The echo output above is shortened for clarity.

Through searching online, I’ve found that most Linux and macOS systems already have /usr/local/bin/ under their PATH variable.

If you already have the folder under the PATH variable but still facing command not found error, then I’d recommend you do a clean install of NodeJS and npm.

First, you need to uninstall npm using the same method you installed it. If you use a package manager like Homebrew, then use brew uninstall node to remove it.

Then you can install your NodeJS and npm using brew install node command.

After a clean install, you should be able to check the NodeJS and npm versions installed on your computer:

$ node -v
v16.3.0
$ npm -v
7.15.1

Now you should be able to do npm install again. Great job on fixing the error!

Npm (node package manager) helps JavaScript developers focus on the code instead of other — sometimes tedious and repetitive — details. Sometimes, however, you may come across npm errors such as npm command not found.

We will work through how to resolve this error, so you can go back to enjoying all that npm has to offer.

Get offers and scholarships from top coding schools illustration

Find Your Bootcamp Match

  • Career Karma matches you with top tech bootcamps
  • Access exclusive scholarships and prep courses

Select your interest

First name

Last name

Email

Phone number

By continuing you agree to our Terms of Service and Privacy Policy, and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.

What is the npm command not found Error?

The Npm command not found error can appear when you install or upgrade npm.

On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node.js installed, have an outdated version, or have permission issues.

Mac users seeing the npm command not found error could be due to missing files on your computer or a permissions issue.

This article addresses those possible reasons. First we cover general causes related to installation, then go into Mac-specific solutions, before addressing how to fix a potential missing PATH variable on Windows.

Check if npm is Installed

The npm command requires npm to be installed on Windows. Npm uses Node.js, so it comes included in your Node.js installation package. To check if you have NOde.js installed type the following in the terminal:

The -v stands for “version”. Visit the npm site to verify if the version of npm you have installed is the latest version.

You may have accidentally deleted your npm file or moved its location. This can happen more often than you think, especially if you change your PATH on your system.

Check if npm is installed as well as node by typing the following in your terminal:

If you do have npm installed, it will output the version on your computer. To install npm, run the commands here for Mac and here if you are using Windows.

Update npm

Even though npm comes with Node.js, they are separate, meaning you can have the latest of one and not of the other, since they may have different update release dates.

If you have node (check with $node -v) and your node commands work, you may need to simply update npm. Updating npm can be done with one line:

npm install npm@latest -g

If you have trouble with this command, you may have to prefix it with sudo:

sudo npm install -g npm@latest

If you are working on your code in an editor, make sure to restart it after you’re done installing or updating.

Windows Solution

You may still see npm command not found because C:Program Filesnodejs could be missing from your PATH environment variable.

  1. Open global search 🔎 and look up “Environment Variables”.
  2. Choose “Edit system environment variables”.
  3. Click “Environment Variables” in the “Advanced” tab.
  4. In the “System Variables” box, search for Path and edit it to include the path C:Program Filesnodejs. If you don’t see it there click “New” then add this path. (Note: Depending on your version you may just need to edit and append this path to what’s there by prefixing it with a semicolon. You’ll see the other paths there are also separated by semicolons).

Here is some documentation on the Windows settings and environment variables relating to npm in case you are curious and want to read more about the settings.

Permissions Solution

For permission issues, prefix your terminal commands with sudo to bypass issues. Permission issues can be the cause of program files not being able to be properly downloaded. You can also try the following terminal commands as a last option if all others have not worked out for you, though this may not be an option for you if you are on a shared or work computer. For Mac and Linux users:

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

This command adjusts the permissions of the npm directory. Chown means change owner, -R means recursively (throughout the files therein), “whoami” grabs your user account name, and the last line is where your node package files are. After running the above command,  try the npm command you were attempting again.

Conclusion

After implementing any changes we went through to troubleshoot the “command not found” error, be sure to restart any open code editor or terminal/command prompt. To recap, the suggested solutions we discussed were:

  • updating npm
  • checking if node is up to date
  • fixing the PATH in Windows
  • changing permissions for node 

This article has instructional links on how to uninstall and install npm for Windows or Mac. If you can do this, it may clear any blockers npm is having.

If you want to dive into npm, read this article on npm which includes curated, proven resources for learning more.

If you are trying to work on a project in Node.js, and encountering the error ‘npm command not found’ you may have improperly installed the npm repository. In this article, you will find information about JavaScript, Node.js, and npm, as well as the solution to the ‘npm command not found error’. Step-by-step solutions are provided below for the three major operating systems, Windows, Linux, and Mac.

npm command not found error message

JavaScript, Node.js, and npm

npm is the package manager that is associated with JavaScript, and specifically the interpreter Node.js. npm is a repository allowing developers to publish their Node.js projects online, where any other developer or community member can access them. The npm repository hosts both open-source and paid packages.

npm logo

JavaScript is a very popular programming language. JavaScript has been a primary language used to make web applications interactive since HTML5 became standard around 2010. Over the last 10 years, many JavaScript front-end frameworks have been developed, such as Vue, Angular, React, and React Native. A few back-end frameworks have been developed for JavaScript, such as Next, Meteor, and Express. Frameworks allow developers to access a suite of code libraries, to improve development timelines. Instead of writing common code from scratch each time, libraries provide that code already, allowing developers to instead focus their attention on coding custom content and actions.

Node.js is not a back-end or front-end framework, instead Node.js is a runtime environment. Yet, Node.js is the most popular for back-end development of applications. The runtime environment can handle hundreds of calls in the loop simultaneously without waiting for an API to respond. Node.js was developed in 2009 using Google’s V8 JavaScript engine (from Chrome). Since then, Node.js has been adopted by many large companies. Amazon Web Services (AWS) which provides about 33% of all web services, uses Node.js. Walmart, Yahoo!, Microsoft, PayPal, and Netflix are just a few of the other major companies using this runtime environment. 

node.js logo

What causes the ‘npm command not found’ error?

This article has been organized into solutions for different operating systems, to provide an easier way for you to find the solutions that are pertinent to your system. The causes are primarily the same across Windows, Linux, and Mac, but the methods are different.

There are four main causes that can trigger the ‘npm command not found’ error:

  1. npm package manager is not installed
    • When you install Node.js on Windows, npm should automatically be included. However if you selected custom install and didn’t select to install the npm package manager, you may not actually have npm on your system.
    • Unlike Windows, npm is not automatically installed on Linux distributions. If you didn’t select to install npm, the error will continue to appear until you install it.
  2. PATH and system variables are not set correctly
    • When you install Node.js on Windows, the PATH and system variables are automatically set, but if you selected custom install and didn’t select ‘Add to PATH’ you may have an incorrectly set PATH.
  3. Outdated version of Node.js
    • If Node.js is outdated, this can cause the npm package manager commands to fail.
  4. A permission issue is preventing the use of npm commands
    • For Mac and Linux operating systems, you may need to adjust permissions for your npm directory.

Windows Operating System

The following solutions are for users and developers trying to solve the ‘npm command not found’ error on a Windows operating system. As Windows 10 is the most updated and supported version of Windows, the step-by-step instructions use Windows 10.

1. Verify/Install Node.js and npm

Before going any further and trying any other solutions, it’s important to verify that Node.js and npm are installed on your system:

  1. Right-click on the Windows icon on the taskbar. Select Windows PowerShell (Admin).
windows powershell admin
  1. Enter “node -v” and Windows Powershell will print the Node.js version number.
  2. Enter “npm -v” to print the npm version number.
  3. If both of the above commands report version numbers, then Node.js and npm are on your system.
  4. Otherwise, you will need to download the installer for Windows (x64). Run the installer and follow the prompts to install the default settings. Npm package manager should be installed with Node.js, as well as online documentation shortcuts, and it will be added to PATH.

2. Check PATH and system variables

To check and fix PATH and system variables for Node.js on Windows:

  1. Click on the Windows icon on the taskbar and search environment variable. Click open for the option listed as Edit the system environment variables.
edit the system environment variables
  1. The System Properties window will open. Select the Advanced tab and then Environment Variables…
system properties
  1. In the Environment Variables window, under System variables, select Path, then Edit…
environment variables
  1. Search the list for C:Program Filesnodejs. If this path doesn’t exist, you need to create a new one.
edit environment variable
  1. Click New…, then input a Variable name. For the Variable value enter “C:Program Filesnodejs“. Now click OK

3. Update Node.js

Outdated versions of Node.js can cause serious issues. To upgrade Node to the latest version:

  1. Right-click on the Windows icon on the taskbar. Select Windows PowerShell (Admin).
  2. Run the following commands to update Node.js and npm:
    • Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    • npm install -g npm-windows-upgrade
    • npm-windows-upgrade
  3. After any packages install and update, check your version of Node.js to ensure it’s updated by entering “node -v“.

Linux Operating System

There are many Linux distributions available, but for the purpose of simplicity, this article will focus on solutions for Ubuntu. Ubuntu boasts the largest Linux distribution market share and has been around since 2004. Other popular distributions include Manjaro, Linux Mint, and Red Hat, but much of the solutions will be applicable to these distributions as well. The solutions are specifically for Ubuntu 20.04.

Below are four solutions to solve the ‘npm command not found’ error on Ubuntu:

1. Install Node.js and npm

Installing Node.js and npm on Ubuntu is fairly simple:

  1. Open a terminal window pressing CTRL+ALT+T simultaneously. Alternatively you can navigate to the Activities menu and search terminal, then clicking on the resulting icon for terminal.
  2. Type the following commands:
    • sudo apt update
    • sudo apt install nodejs npm
  3. When the packages are finished installing, you can verify that both Node.js and npm are installed by entering:
    • node –version
    • npm –version

In this solution, the sudo command gives the user elevated permissions (the same as an administrator). Now that Node.js and npm have been installed and verified, you can attempt to run an npm command.

2. Check PATH and system variables

You now know that npm is correctly installed on your system. Next we will verify the default path for the npm command:

  1. Open a terminal window pressing CTRL+ALT+T simultaneously. Alternatively you can navigate to the Activities menu and search terminal, then click on the resulting icon for terminal.
  2. To check the current path for npm commands enter “which npm“.
  3. The /etc/environment file needs to be checked for the file path from above, which may look something like /usr/bin/npm. Enter “cat /etc/environment“.
  4. This will give you a readout of your environment variable. You want to find the same file path from step 2, in your environmental variable. If not, continue on to add the npm path.
  5. To edit the /etc/environment file enter “vi /etc/environment“.
  6. Now you need to add a colon(:) and the npm path from step 2 to the end of the environmental file. This path file should end at ‘bin’. Make sure this path is before the end of the quotes.
  7. Enter “source /etc/environment” to reload the file with the changes.

3. Give User Permissions to Run Commands

Linux has been designed to be a secure operating system, because most applications have very limited permissions. Sometimes this can cause interference with how programs work. To give yourself permissions to edit node modules (where npm is located):

  1. Open a terminal window pressing CTRL+ALT+T simultaneously. Alternatively you can navigate to the Activities menu and search terminal, then click on the resulting icon for terminal.
  2. Enter “sudo chown -R $(whoami):admin /usr/local/lib/node_modules/“.
  3. Attempt to run an npm command and see if the problem reoccurs.

4. Update Node.js

Finally, older outdated versions of Node.js can cause version issues. To upgrade Node to the latest version, you will use npm:

  1. Open a terminal window pressing CTRL+ALT+T simultaneously. Alternatively you can navigate to the Activities menu and search terminal, then click on the resulting icon for terminal.
  2. Enter “sudo npm cache clean -f” to clear your current cache so that there are no problems accessing the correct file path, if you changed it in the second solution.
  3. Now enter “sudo npm install npm@latest -g“.
  4. You can verify that Node updated to the latest version by entering “npm -v“.

MacOS

1. Install Node.js and npm

Homebrew is a highly popular package manager for MacOS. If you have Homebrew installed on your Mac computer, it is very easy to install Node.js. You should strongly consider downloading Homebrew if you don’t have it. This solution will show you how to install Homebrew, as well as Node.js and npm:

  1. Click the Launchpad icon in the Dock, then search for Terminal. Click the result for Terminal.
  2. Type in the following command into your Terminal window to install Homebrew:
    • /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
  3. Then enter:
    • brew update
    • brew install node
  4. To verify that both are installed, enter “node -v” and “npm -v” to confirm the version of both Node.js and npm.
  5. Check if the ‘npm command not found’ error remains.

Alternatively you can find and use the Node.js installer for macOS.

2. Check PATH and system variables

For macOS, npm is usually found under /usr/local/bin. To check your PATH variable:

  1. Click the Launchpad icon in the Dock, then search for Terminal. Click the result for Terminal.
  2. Into the terminal enter echo $PATH, to display your PATH variable.
  3. Now enter “npm get prefix“. Compare the two outputs. Most likely the npm get prefix command will report /usr/local/bin. This should also be found in your PATH variable.
  4. If the prefix is NOT found in the PATH variable, it needs to be set. To set your PATH enter “export PATH=”[prefix]/bin:$PATH” >> ~/.bash_profile“. [prefix] is the value returned in step 3. Now enter “source ~/.bash_profile“.
  5. Check to see if the ‘npm command not found’ error is now resolved by trying the same command that failed previously.

3. Give User Permissions to Run Commands

MacOS shares a lot of similarities with Linux. Like Linux, you may need to give yourself permissions to edit node modules to bypass this error:

  1. Click the Launchpad icon in the Dock, then search for Terminal. Click the result for Terminal.
  2. Enter “sudo chown -R $(whoami):admin /usr/local/lib/node_modules/“.
  3. Attempt to run an npm command and see if the problem reoccurs.

4. Update Node.js and npm

If you installed Homebrew from the first MacOS solution, this will be extremely simple. If you don’t have Homebrew or another package manager like Nvm or N, you need to visit the Node.js website to find the newest installer for the updated version. Make sure to follow the default installation settings and don’t choose custom install unless you know what you are doing.

  1. If you have Homebrew, click the Launchpad icon in the Dock, then search for Terminal. Click the result for Terminal.
  2. Enter “brew upgrade node“.
  3. That’s it! Double-check by entering “node -v” and “npm -v” to ensure you are up-to-date.

Key Takeaway

The ‘npm command not found’ can be a major pain when you are working to develop an application and can’t access an important directory like npm. Without npm you don’t have access to the libraries for Node.js, and will spend significant extra time coding simple and common features by hand.

This article was broken down into three major sections for the operating systems Windows, Linux, and MacOS. This was to allow you easy access to solutions that would be helpful for your system, without requiring you to wade through non-useful information.

The four primary causes of the ‘npm command not found’ error are Node.js and/or npm not installed, path and system variables not set properly, outdated Node.js, and permissions conflicts. The solutions across all three operating systems are fairly simple and straightforward. If you were not familiar with command line (terminal, bash, etc) commands, you may have learned some useful commands in these solutions. Let us know in the comments section which solution worked, or if we have left out anything!

I was trying to start a new React Native project the other day, when I got this error message:

$ create-react-native-app my-fancy-project
-bash: create-react-app: command not found

What the frak does that mean?

Apparently this problem stems from NPM not being able to find the files needed to perform this operation. It turns out that I didn’t have a correct
path set on my machine.

Step 1: Finding your way

In order to fix this you first need to find out where you keep all your NPM stuff. One way to do this is by using the ‘npm config get prefix’ command in
your CLI, which will return the path to your NPM folder. It might look a little something like this:

$ npm config get prefix
C:Users[your name]AppDataRoamingnpm //your file path

Copy the path, we’re going to need it later.

Step 2: Set your path

This tutorial is specific for Windows 10. This might work the same way in older Windows versions, but I haven’t tried it out. If you’re running MacOS —
you’re on your own. If you’re running Linux, you’ve probably solved this problem yourself and I’ve no idea why you’re reading this blog post.

Open File Explorer, right click “This PC” and select “Properties”

The right click menu of This PC

Click “Advanced system settings”

Computer properties

Go to the “Advanced” tab, click the “Environment Variables” button

System properties window

In the “User variables” section, double click the “Path” row.

NOTICE! Do not, I repeat, DO NOT tinker with the “System variables” section. You could really mess things up if you don’t know what you’re doing.

Environment variables window

Double click an empty row in the newly opened window and paste the path you copied earlier. Make sure to not edit or delete any of your other paths,
it could mess up other installations such as Java, Ruby, emulators, SDKs etc.

Edit environment variables window

Press OK. Back at the “System Properties” window, click apply.

Restart your CLI. Your machine should now be able to locate your NPM folder!

How to fix the NPM command not found error?

List of content you will read in this article:

  • 1. What is NPM
  • 2. Solutions to the “npm command not found” error
  • 3. Conclusion

NPM is a top-rated package manager for Node.js applications. However, in some cases, a user may find trouble installing it or, by any chance, finds it difficult to resolve the “npm package missing” error. This article will go through different solutions that can help you fix this common issue quickly. 

What is NPM

NPM, or Node Package Manager, is a NodeJS package manager. A package manager allows you to specify the dependencies for your project, stating that this tool or site requires these specific third-party components in order to run (or develop). It will then figure out what they need and download it for them automatically. The following are major advantages of using the npm package manager:

  • It deals with recursive dependencies.
  • The dependencies can be re-assembled as needed and do not need to be stored in your repository.
  • You can easily specify and change the version of these packages on which you rely.

Solutions to the “npm command not found” error

This is a standard error that people face in any Operating System. There can be many reasons for this error: system or path variable has been modified, installation mistake, permission issue, etc. Let’s look at possible fixes for this error.

Solution 1 on Windows

Go to this website and download Node.js. Select “Windows Installer” with the “.msi” extension and choose your suitable architecture from 64 or 32-bit options. 

Once Node.js has been installed, the installation procedure will start. Accept the terms and click on Next.

The following dialogue will ask you for the location of the installation of Node.js. Choose any location that suits you.

The following window will ask you to install additional tools along with Node.js. Leave it as the default unless very necessary.

The following window will ask you to install Chocolatey along with Node.js. Again, leave it as the default unless very necessary.

The following window will ask you to start the installation. Click on Install. The installation will then begin.

After installation, verify the npm installation using the following command

> npm -v

Solution 2 for Windows

The path variables are by default added in Windows while installing Node.js. However, some other processes can cause it to get removed or modified. 

To fix this, go to Edit the system environment variables from the Start menu.

 

A new dialogue box saying System Properties will appear. Click on the Environment Variables option from it. 

Select the option named Path from the list and click on Edit.

If the path for Node.js is not present, click on New and paste the location of the Node.js folder. In our case, it was “C:Program Filesnodejs.”

Solution 1 for UNIX-like systems

For Linux users, type the following sequence of commands to install npm and Node.js

$ sudo apt-get update

$ sudo apt-get install nodejs

$ sudo apt-get install npm

Solution 2 on UNIX-like systems

There can be permission issues in UNIX-like systems. 

To give the required permission to the user, type the below commands on respective Operating Systems and press Enter.

Mac:

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

Linux:

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

Solution 3 on UNIX-like systems

You might also not be using the latest version of npm. Run the following command to upgrade npm:

$ sudo npm install npm@latest -g

Conclusion

This article went through various solutions for the “npm command not found” error. We saw how we could install it from scratch and configure some settings if it is already installed and fix this issue. We covered aspects like permission issues, installation issues, path variable issues to fix this error.

People also read:

  • How to install Node.js and NPM 
  • How to update the NPM package manager
  • How to check the NPM version

Понравилась статья? Поделить с друзьями:
  • Bash java command not found windows
  • Bash gulp command not found windows
  • Bash cmake command not found windows
  • Baseus ccall bt01 драйвер для windows 7
  • Baseus bluetooth adapter driver windows 10