Npm not found zsh

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

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.

Step2- Install Node.js and npm

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

Step2.1 – Accept 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.

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.

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

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

Step 3 – Check npm and node Js version.

Read more: Elegant cross nail designs

Check node js version

C:> node -v

Check npm (node package manager) version

C:> npm -v

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

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

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 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

Read more: Where is ray liotta buried

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

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

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.

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.

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.

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.

Read more: Err ossl pem no start line

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 [email protected] -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 -1index.jspackage-lock.jsonpackage.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 @[email protected]^1.3.0: npm ERR! Verification failed while extracting @[email protected]^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.

FAQs:- NPM command not found

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.

Related Posts