| by Arround The Web | No comments

NPM Command Not Found

NPM or Node Package Manager is a fantastic tool that helps JavaScript developers download, install, uninstall, and update packages.

NPM holds one of the largest JavaScript registries that helps you easily search and manage packages.

This tutorial will go over the solutions you can try when you encounter the “NPM command not found” error.

What causes this error?

In most cases, this type of error occurs when the system cannot find the path where npm or NodeJS is installed.

This could be because you don’t have npm or NodeJS installed on your system or haven’t configured the PATH to binaries.

Ensure npm is installed

The first step to resolving this type of error is to ensure that you have npm installed on your system.

You only need to install NodeJS as it comes packaged in most cases. To check if NodeJS is installed, run the command:

$ node -v

If NodeJS is installed on your system, the command above should produce the installed Node version.

If you get an error, you do not have it installed on your system.

Installing NodeJS and NPM on Windows

To install npm and NodeJS on your windows system, open your browser and navigate to the resource below:

https://nodejs.org/en/download/

Select the installer for your system and download it.

Launch the installer package once the download is complete and follow along with the setup wizard.

Under “Custom Setup,” select Add to PATH and set it to “Entire feature will be installed on the local hard drive.”

Follow the following steps, click install a begin the installation process.

Check Node and NPM versions.

Once the installation is complete, open your terminal window and run the commands:

$ node -v

The command above should return the installed Node Version

$ npm -v

The above should print the installed npm version.

Windows Manually Add Node and NPM to Path

On Windows, you may face the “npm command not found” error if the path to nodejs and npm are not added to your path variable.

To fix this, locate the path to nodejs and npm binaries.

By default, NodeJS is installed inC:\Program Files\nodejs

Open the command prompt and run the command below to add it to your path

$ set PATH=%PATH%;"C:\Program Files\nodejs"

The command above should add the specified directory to the path variable.

Installing NodeJS and NPM on Linux

On Linux, you can use your package manager to install nodejs and npm as shown:

$ sudo apt-get update
$ sudo apt-get install nodejs npm -y

Once completed, verify nodejs and npm are accessible by checking the versions.

Fix “npm command not found” error – Permissions

In some instances, you may face the “npm command not found” error due to directory permissions.

On Linux, you can fix it by running the commands:

$ sudo chown -R $(whoami):root $(npm root -g)

The command above should change the permissions of the npm global package location to the current user.

On macOS, you can run the command:

$ sudo chown -R $(whoami):admin $(npm root -g)

Conclusion

This article explored various possible causes of the “npm command not found” error. We also dove into details on different methods and techniques you can use to fix it.

Share Button

Source: linuxhint.com

Leave a Reply