List of content you will read in this article:
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 Files\nodejs.”
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.
$ sudo chown -R $(whoami):admin /usr/local/lib/node_modules/
$ 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
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: