I’m learning laravel and follwing this tutorial,
But when I went try and install npm, is says bash: npm: command not found
Henke
4,1673 gold badges31 silver badges40 bronze badges
asked Aug 9, 2017 at 8:07
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 MaskBlack Mask
3413 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
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
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!
answered Aug 28, 2018 at 13:06
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
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
VoontentVoontent
6995 silver badges8 bronze badges
1
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-aplussan-apluss
4754 silver badges9 bronze badges
0
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
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 SisicMirza Sisic
2,3914 gold badges24 silver badges37 bronze badges
maybe vscode config shell failed, you can try restart it.
answered Apr 21 at 2:56
Joker BiJoker Bi
4074 silver badges9 bronze badges
If you’re a Node.js developer, npm is an essential package manager that helps you install and manage modules for your applications. However, encountering the «npm command not found» error can be frustrating and prevent you from using npm. This error occurs when your computer cannot locate the npm executable file, which could result from installation problems, system path issues or permission limitations.
Before you attempt to resolve this issue, ensure that both Node.js and npm are installed on your computer by typing «node -v» and «npm -v» in a terminal or command prompt window. If these commands don’t work, download and install the latest versions of Node.js and npm for your operating system.
If Node.js and npm are already installed, but you’re still getting the error message, it’s possible that your computer can’t find the executable file because of system path issues. You can solve this by adding the directory containing the npm executable file to your system path by editing the PATH environment variable. The steps to take this will differ depending on your operating system.
Alternatively, if there is a corrupted installation of npm on your computer due to installation problems or update issues, strange behaviour with using npm commands or error messages may occur. In such cases, fixing a corrupted installation should resolve the problem by executing “npm” command without difficulty.
Introduction
NPM is a package manager for node.js. It helps you to install packages or modules for Node.js applications.
You get an npm error, when your operating system can’t find the npm executable. If you are getting any of the following errors related to npm, follow the article —
- 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 —
- Npm and Node.js are not installed
- System PATH is not setup correctly
- Permission issues
- No package.json file describing the dependencies
- Integrity check failed error
Tutorials, 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 the npm command not found in Windows 10/11
If you don’t know the prerequisite 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.
Check out my script to automatically fix your npm errors for Linux and Mac users. Else you can look for these manual methods.
Let me show you the correct way of npm installation in Windows.
How to install Node.js on Windows 10/11
Step1 — Download Node.js
Download Node.js software from the nodejs.org website. The latest LTS version is node-v18.16.0 as per the nodejs website. The package npm 9.5.1 is included with node.js, so you don’t need to install it separately.
Step2— Install Node.js and npm
Double-click installer node-v18.16.0-x64.msi and follow the installation wizard.
Step 2.1 — Accept the terms in the license agreement and click next.
Step 2.2 — Select the destination folder for node.js installation. The default location of node.js is «C:Program Filesnodejs«. I will recommend keeping it default.
Step 2.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.
Step 2.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 the npm and Node.js versions.
Open the command prompt and run the following commands to confirm node.js and npm installation.
Check the node js version
C:> node -v
Check the 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 the npm command not found error in Linux
I have taken an example of Ubuntu 22.04 OS for output shared in the tutorial.
Debian-based Linux Distributions
- Open a terminal window on your Debian-based Linux distribution.
- Update the package list by running the following command:
sudo apt update
- Install the Node.js package by running the following command:
sudo apt install nodejs
. It will install the npm package also. - Verify that Node.js and npm are installed by running the following commands:
node -v
(This should print the version number of Node.js.)npm -v
(This should print the version number of npm.)
Below-mentioned is the screenshot for your reference. I have installed the latest version of node v19.9.0 and npm 9.6.3 for Ubuntu 22.04
Red Hat based Linux Distributions
- Open a terminal window on your Red Hat based Linux distribution.
- Update the package list by running the following command:
sudo dnf update
- Install the Node.js package by running the following command:
sudo dnf install nodejs
. The NPM package will automatically install - Verify that Node.js and npm are installed by running the following commands:
node -v
(This should print the version number of Node.js.)npm -v
(This should print the version number of npm.)
Congrats! you have fixed the «Bash or sudo: npm command not found» error by installing npm and Node.js.
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 Node Source repository
Solution 3 — How to Fix npm command not found error on macOS
Run node -v and npm -v commands to check the existing installation, if you are still facing npm-related errors, you can remove the existing installation and then install it again.
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 errors in macOS. Watch out for the official node source 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 PATH variables for npm in the case of Ubuntu 22.04
How to check the npm path variable in Ubuntu 22.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 the 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 the npm path till bin folder at the end of the environment file, separated by a colon «:». Save and exit from the file. Make a note, the 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
First, you need to make sure, node js and npm are installed in Windows. If it’s already there, you need to follow these steps
Step1 — Search for the environment variable
Step1.1 — Type «environment variable» in the search box and click open.
Step 1.2 — Click on «Environment variables» in the Advanced tab of System Properties.
Step 1.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 the 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.
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/
or
$ sudo chown -R $(whoami) ~/.npm
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 a 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, 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.
Frequently asked questions
-
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 the npm and Node.js packages as recommended, or set up the npm path variable to resolve it.
-
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
-
NPM is not recognized as an internal or external command.
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 and Linux.
-
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.
-
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 the «npm command not found error». Either npm is not installed or your path variable is not set up correctly.
-
Why is npm not working even after installing Node.js?
This could be due to a problem with your system path. Make sure that the directory containing the npm executable file is added to your system path.
-
What should I do if I still get the «npm command not found» error after following these steps?
If you’ve tried all the steps above and are still having issues, then it might be worth posting on a forum or reaching out to the Node.js community for help.
-
Can I use a different package manager besides npm?
If you are still having issues with your npm installation, you can try using a package manager like yarn. Yarn is an alternative package manager that is compatible with npm and can be used as a drop-in replacement. You can install yarn using the following command:
npm install -g yarn
Once the yarn is installed, you can use it to install packages in place of npm.
Conclusion
In this tutorial, we discussed the causes of the «npm command not found» error and how to fix it. If you encounter this error, the first thing you should check is the installation of Node.js and npm. If the installation is successful, check the path and permission issues. By following the steps mentioned in this article, you should be able to fix the «npm command not found» error and continue your work with Node.js and npm.
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.
Also see: “Can’t set headers after they are sent to the client” error in Express.js – possible solutions
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).
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.
In the System Properties window , switch to Advanced tab and select Environment Variables…
In the Environment Variables window, under System variables, look for Path or PATH system variable, then select Edit….
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
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.
- Right-click on the Windows icon on the taskbar. Select Windows PowerShell (Admin).
- 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
- 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.
“npm: Command not Found” is one of the most basic errors we face while getting started with Javascript. We may get this error while installing the node package manager. Node and npm packages are not related to nodejs and therefore not included in the nodejs package. NPM stands for Node Package Manager. Node.Js is an open-source, Cross-platform, Javascript runtime environment. npm is used to install the different versions of our favorite third-party packages.
This error simply means that npm is not installed on our Linux machine. We need to install npm on our machine.
Fixing Sudo npm: Command not Found on Linux
There are 2 methods through which we can solve this error.
- Download npm from Linux/Ubuntu Repository
- Build NodeJs from the source
Method 1: Download npm from Linux/Ubuntu Repository
To install npm on Linux/Ubuntu, simply execute the following command on our Linux terminal.
sudo apt install npm
After execution, the npm package will be installed on the Linux system and our error will be fixed.
Method 2: Build from Source
This is a bit longer process but this might make us independent of the availability in Linux/Ubuntu Repository. Here is the NodeJs official Repository:
https://github.com/nodejs/node
Note: We must have git installed to build it from the source.
Step 1: See all the available versions of NodeJs.
git ls-remote https://github.com/nodejs/node | grep tags | less
Press ‘q’ to exit the list.
Step 2: Now clone a specific version of Node (without full history).
git clone –depth 1 –branch v15.11.0 https://github.com/nodejs/node
Step 3: Navigate to the repository using the following command.
cd node
Step 4: Now execute the following commands for configuration and installation.
./configure
make -j12 # We can use j4 or j8 depending on our CPU Count
sudo make install
This might take some time. Once done, we will see a similar result as the Ubuntu Repository result.
Note: Whenever we use sudo, it prompts us for our password. Make sure, in Linux, that our password * isn’t visible. Type our password and press Enter. It should work fine.
Last Updated :
25 May, 2022
Like Article
Save Article
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!