Node is JavaScript’s most used runtime environment for ser-side programming and scalable network applications. NPM is an acronym for Node Package Manager. It is famous as a package manager for JavaScript. You may get the “npm command not found” when you are working on node. Let’s figure out how to solve the “npm command not found” On all platforms.
What causes the error?
The error “npm command not found” appears when the system is unable to find the path where node.js or npm is installed. The two possibilities that cause the error is either you don’t have it installed in the system or PATH (environment variable) is not configured to binaries (executable files). Every operating system has put binaries for simple searching in certain places.
How To Fix the Error “npm command not found” On All Platforms
We have to look at ways to handle the error on all major platforms. Let’s check out
Solve the Error in Windows
If you are using Windows, you need to go to the official website to download the latest node.js version. The NPM package is built-in so it is not needed to separately install it. if you are using a 32- bit Windows, then download the version accordingly, or else go for the 64-bit version.
Set Path
Open the control panel and click on the System. Here, tap Advance System Settings. In systems property. Select Environment Variables. Choose the path variable from the System Variables or User Variables table and tap the button Edit…
Add c:\Program Files\node.js to the path variable as a new entry. Tap Ok and restart your PC to make the functions run successfully.
Solve the Error in macOS
If you macOS user, then you need to install Node.js for macOS from the official site. You just need to download it and open the installer file. After opening the installer file, you have to follow the instructions coming up on the screen to successfully install the setup.
Set Path
You just need to open the terminal and open the file /etc/paths. Like this:
sudo nano /etc/paths
If it doesn’t have the ‘/usr/local/bin’ directory, you need to add it. Once done, save the file. Now, log out for the changes to work properly. Login again and it works fine without the error.
Solve the Error in Linux
On a few distributions, the npm is a built-in option with node.js. While a few needs you to install npm separately. Have a look at the following commands to install node.js as well as npm
To install on Linux Mint, Debian, and Ubuntu, follow the commands
$ sudo apt install npm nodejs
OR
$ sudo apt install npm
To Install npm on Red Hat, CentOS 8, and Fedora, use the below commands
$ sudo dnf install npm
Or
$ sudo dnf install nodejs
To install npm on Arch Linux, use this command:
$ sudo pacman -S npm
On OpenSUSE, use this:
$ sudo zypper install nodejs14
On FreeBSD, follow this:
$ sudo pkg install node
Set Path
Once you download from the official website, the chances are quite low to not find the binary of npm. In order to display the path variable, you need to use the echo command
$ echo $PATH
It shows the following
/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin
You have your npm either placed in /usr/bin or /usr/local/bin. In case you have it included in the path, you have to add it again by shell configuration file editing.
You need to follow this command
export PATH=$PATH:/usr/local/bin:/usr/bin
to ~/.profile, ~/.bashrc/, or ~/.bash_profile. Log out and log in to your system again.
Conclusion
And that’s how you fix the error “npm command not found” on all platforms. You can simply follow the steps according to the system you are using.
I hope it helps!