Sudo apt install npm error

I am trying to upgrade my nodejs to 7.6 but failed. Now I have a new problem after re-installing node 6.10: $ sudo apt-get purge nodejs npm Reading package lists... Done Building dependency tree ...

I am trying to upgrade my nodejs to 7.6 but failed. Now I have a new problem after re-installing node 6.10:

$ sudo apt-get purge nodejs npm
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'npm' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  linux-headers-4.8.0-40 linux-headers-4.8.0-40-generic linux-image-4.8.0-40-generic linux-image-extra-4.8.0-40-generic
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED
  nodejs*
0 to upgrade, 0 to newly install, 1 to remove and 53 not to upgrade.
After this operation, 51.7 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 278133 files and directories currently installed.)
Removing nodejs (6.9.5-1nodesource1~yakkety1) ...
Processing triggers for man-db (2.7.5-1) ...
(Reading database ... 274476 files and directories currently installed.)
Removing nodejs (6.9.5-1nodesource1~yakkety1) ...
Purging configuration files for nodejs (6.9.5-1nodesource1~yakkety1) ...
dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules' not empty so not removed

Why does it say Package 'npm' is not installed, so not removed? i have been using npm to install many node packages for my projects!!

I ignore the error and went on installing node 7.6:

$ curl -sL https://deb.nodesource.com/setup_7.6 | sudo -E bash - 
bash: line 1: html: No such file or directory
bash: line 2: syntax error near unexpected token `<'
'ash: line 2: `<head><title>404 Not Found</title></head>

So I fell back to node 6.x. But I cannot install npm anymore:

$ sudo apt-get install npm
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies.
 npm : Depends: nodejs but it is not going to be installed
       Depends: node-abbrev (>= 1.0.4) but it is not going to be installed
       Depends: node-ansi (>= 0.3.0-2) but it is not going to be installed
       Depends: node-ansi-color-table but it is not going to be installed
       Depends: node-archy but it is not going to be installed
       Depends: node-block-stream but it is not going to be installed
       Depends: node-fstream (>= 0.1.22) but it is not going to be installed
       Depends: node-fstream-ignore but it is not going to be installed
       Depends: node-github-url-from-git but it is not going to be installed
       Depends: node-glob (>= 3.1.21) but it is not going to be installed
       Depends: node-graceful-fs (>= 2.0.0) but it is not going to be installed
       Depends: node-inherits but it is not going to be installed
       Depends: node-ini (>= 1.1.0) but it is not going to be installed
       Depends: node-lockfile but it is not going to be installed
       Depends: node-lru-cache (>= 2.3.0) but it is not going to be installed
       Depends: node-minimatch (>= 0.2.11) but it is not going to be installed
       Depends: node-mkdirp (>= 0.3.3) but it is not going to be installed
       Depends: node-gyp (>= 0.10.9) but it is not going to be installed
       Depends: node-nopt (>= 3.0.1) but it is not going to be installed
       Depends: node-npmlog but it is not going to be installed
       Depends: node-once but it is not going to be installed
       Depends: node-osenv but it is not going to be installed
       Depends: node-read but it is not going to be installed
       Depends: node-read-package-json (>= 1.1.0) but it is not going to be installed
       Depends: node-request (>= 2.25.0) but it is not going to be installed
       Depends: node-retry but it is not going to be installed
       Depends: node-rimraf (>= 2.2.2) but it is not going to be installed
       Depends: node-semver (>= 2.1.0) but it is not going to be installed
       Depends: node-sha but it is not going to be installed
       Depends: node-slide but it is not going to be installed
       Depends: node-tar (>= 0.1.18) but it is not going to be installed
       Depends: node-underscore but it is not going to be installed
       Depends: node-which but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Any ideas?

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

Table of Contents

  • 1 Solution 1 — How to fix npm command not found in Windows 10
  • 2 Solution 2 — How to fix npm command not found in Ubuntu
  • 3 Solution 3 — How to Fix npm command not found — Mac
  • 4 Solution 4 — Path or system variable changed resulting in npm error
  • 5 Solution 5 — Permission issues on «node_modules»
  • 6 Solution 6 — Old Node version installed
  • 7 Solution 7 — No package.Json file issue
  • 8 Solution 8 — Integrity check failed
  • 9 FAQs:- NPM command not found
  • 10 Conclusion

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.

Download-node-js

Step2— Install Node.js and npm

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

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

node-js-installation-folder

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.

select-npm-to-fix-npm-command-not-found

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

node-js-dependent-native-modules

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

Fix-npm-command-not-found-windows10validating-node-js-and-npm-install

Step 3 — Check npm and node Js version.

Check node js version

C:> node -v 

Check npm (node package manager) version

C:> npm -v

check-node-js-version

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

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

Install-nodejs-using-apt

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

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

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

Check-npm-path

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

set-npm-path-variable-fix-npm-command-not-found

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.

open-environment-variable-windows10

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.

Edit-environment-variable-npm-command-not-found

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.

add-variable-to-solve-npm-command-not-found

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/

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

  1. 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 npm and node js package as recommended or set up the npm path variable to resolve it.

  2. What is the NPM Run command?

    npm run-script or npm run (alias) is the command to execute arbitrary package scripts. npm run-script <command> is the syntax. Without <command>, it will list the available scripts.

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

  4. Is not recognized as an internal or external command NPM?

    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. For non-windows users (Linux or Mac), Install node js first and then the npm package individually.

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

  6. 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 «npm command not found error». Either npm is not installed or your path variable is not set up correctly.

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.

Hello folks, In this article, we will discuss how to solve the error npm: command not found.

What is npm?

npm stands for node package manager. You 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.

So to use the npm and node command, you need to install both packages. In Windows, npm is installed with NodeJS but in Ubuntu, you need to install it separately. You can either install from the Ubuntu repository or node source repository. Follow this article to see both the methods:

Solution 1: Using Ubuntu repository

Open a terminal window by pressing Ctrl+Alt+T. Run the following command to update the Ubuntu repository:

Now, install the nodejs package by running the following command and pressing Y to continue.

Now, install the node package manager i.e. npm. You got the error because npm was not installed. Install it by executing the following command:

That’s it! You will not get the error after successfully installing both packages.

To confirm, check the version of node js and npm. Enter the following command to check the installed version.

npm-4

Solution 2: Using node source repository

To install node js along with npm using node source repository, follow the steps below. I will prefer this method because using node source repository will always install the latest version of node js.

Open a terminal by pressing Ctrl+Alt+T. Update the package repository using the following command:

Now, Install the dependent python libraries by executing the following command:

sudo apt install python3-software-properties

Now install node js PPA or repository by executing the following command:

 curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
npm-7

Replace the setup_16.x with the version you want to install. 15.x is not actively supported anymore i.e. you will not get security and stability updates for the 15.x version. We have installed 16.x version. Installing 15.x will give you a warning message like this.

npm-8

If curl is not installed on your system, you may get an error like curl not found. Install it by executing the following command:

npm-9

Now using the apt command, install node js and npm with a single command i.e. you don’t need to install npm separately here.

sudo apt install -y nodejs

Node JS and npm are installed successfully. Confirm by checking the version of both the packages using the following command:

npm-11

Uninstalling npm in Ubuntu

In case you need to uninstall npm in Ubuntu, You can do so by executing the following command:

Conclusion

So, we discussed both the methods of installing npm in Ubuntu. Both the methods work perfectly fine, but using the node source repository always installs the latest version. Thank you for reading!!

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

How to fix the NPM command not found error?

List of content you will read in this article:

  • 1. What is NPM
  • 2. Solutions to the “npm command not found” error
  • 3. Conclusion

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 Filesnodejs.”

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.

Mac:

$ sudo chown -R $(whoami):admin /usr/local/lib/node_modules/

Linux:

$ 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

Conclusion

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:

  • How to install Node.js and NPM 
  • How to update the NPM package manager
  • How to check the NPM version

Написал команду sudo apt-get install npm и после это выдаёт ошибку.
Что делать?

Некоторые пакеты невозможно установить. Возможно, вы просите невозможного,
или же используете нестабильную версию дистрибутива, где запрошенные вами
пакеты ещё не созданы или были удалены из Incoming.
Следующая информация, возможно, поможет вам:

Пакеты, имеющие неудовлетворённые зависимости:
npm : Зависит: nodejs но он не будет установлен
Зависит: node-abbrev (>= 1.0.4) но он не будет установлен
Зависит: node-ansi но он не будет установлен
Зависит: node-archy но он не будет установлен
Зависит: node-block-stream но он не будет установлен
Зависит: node-fstream (>= 0.1.22) но он не будет установлен
Зависит: node-fstream-ignore но он не будет установлен
Зависит: node-github-url-from-git но он не будет установлен
Зависит: node-glob (>= 3.1.21) но он не будет установлен
Зависит: node-graceful-fs (>= 2.0.0) но он не будет установлен
Зависит: node-inherits но он не будет установлен
Зависит: node-ini (>= 1.1.0) но он не будет установлен
Зависит: node-lockfile но он не будет установлен
Зависит: node-lru-cache (>= 2.3.0) но он не будет установлен
Зависит: node-minimatch (>= 0.2.11) но он не будет установлен
Зависит: node-mkdirp (>= 0.3.3) но он не будет установлен
Зависит: node-gyp (>= 0.10.9) но он не будет установлен
Зависит: node-nopt (>= 2.1.1) но он не будет установлен
Зависит: node-npmlog но он не будет установлен
Зависит: node-once но он не будет установлен
Зависит: node-osenv но он не будет установлен
Зависит: node-read но он не будет установлен
Зависит: node-read-package-json (>= 1.1.0) но он не будет установлен
Зависит: node-request (>= 2.25.0) но он не будет установлен
Зависит: node-retry но он не будет установлен
Зависит: node-rimraf (>= 2.2.2) но он не будет установлен
Зависит: node-semver (>= 2.1.0) но он не будет установлен
Зависит: node-sha но он не будет установлен
Зависит: node-slide но он не будет установлен
Зависит: node-tar (>= 0.1.18) но он не будет установлен
Зависит: node-which но он не будет установлен
E: Невозможно исправить ошибки, у вас отложены (held) битые пакеты.

node.js установил

If you are trying to work on a project in Node.js, and encountering the error ‘npm command not found’ you may have improperly installed the npm repository. In this article, you will find information about JavaScript, Node.js, and npm, as well as the solution to the ‘npm command not found error’. Step-by-step solutions are provided below for the three major operating systems, Windows, Linux, and Mac.

npm command not found error message

JavaScript, Node.js, and npm

npm is the package manager that is associated with JavaScript, and specifically the interpreter Node.js. npm is a repository allowing developers to publish their Node.js projects online, where any other developer or community member can access them. The npm repository hosts both open-source and paid packages.

npm logo

JavaScript is a very popular programming language. JavaScript has been a primary language used to make web applications interactive since HTML5 became standard around 2010. Over the last 10 years, many JavaScript front-end frameworks have been developed, such as Vue, Angular, React, and React Native. A few back-end frameworks have been developed for JavaScript, such as Next, Meteor, and Express. Frameworks allow developers to access a suite of code libraries, to improve development timelines. Instead of writing common code from scratch each time, libraries provide that code already, allowing developers to instead focus their attention on coding custom content and actions.

Node.js is not a back-end or front-end framework, instead Node.js is a runtime environment. Yet, Node.js is the most popular for back-end development of applications. The runtime environment can handle hundreds of calls in the loop simultaneously without waiting for an API to respond. Node.js was developed in 2009 using Google’s V8 JavaScript engine (from Chrome). Since then, Node.js has been adopted by many large companies. Amazon Web Services (AWS) which provides about 33% of all web services, uses Node.js. Walmart, Yahoo!, Microsoft, PayPal, and Netflix are just a few of the other major companies using this runtime environment. 

node.js logo

What causes the ‘npm command not found’ error?

This article has been organized into solutions for different operating systems, to provide an easier way for you to find the solutions that are pertinent to your system. The causes are primarily the same across Windows, Linux, and Mac, but the methods are different.

There are four main causes that can trigger the ‘npm command not found’ error:

  1. npm package manager is not installed
    • When you install Node.js on Windows, npm should automatically be included. However if you selected custom install and didn’t select to install the npm package manager, you may not actually have npm on your system.
    • Unlike Windows, npm is not automatically installed on Linux distributions. If you didn’t select to install npm, the error will continue to appear until you install it.
  2. PATH and system variables are not set correctly
    • When you install Node.js on Windows, the PATH and system variables are automatically set, but if you selected custom install and didn’t select ‘Add to PATH’ you may have an incorrectly set PATH.
  3. Outdated version of Node.js
    • If Node.js is outdated, this can cause the npm package manager commands to fail.
  4. A permission issue is preventing the use of npm commands
    • For Mac and Linux operating systems, you may need to adjust permissions for your npm directory.

Windows Operating System

The following solutions are for users and developers trying to solve the ‘npm command not found’ error on a Windows operating system. As Windows 10 is the most updated and supported version of Windows, the step-by-step instructions use Windows 10.

1. Verify/Install Node.js and npm

Before going any further and trying any other solutions, it’s important to verify that Node.js and npm are installed on your system:

  1. Right-click on the Windows icon on the taskbar. Select Windows PowerShell (Admin).
windows powershell admin
  1. Enter “node -v” and Windows Powershell will print the Node.js version number.
  2. Enter “npm -v” to print the npm version number.
  3. If both of the above commands report version numbers, then Node.js and npm are on your system.
  4. Otherwise, you will need to download the installer for Windows (x64). Run the installer and follow the prompts to install the default settings. Npm package manager should be installed with Node.js, as well as online documentation shortcuts, and it will be added to PATH.

2. Check PATH and system variables

To check and fix PATH and system variables for Node.js on Windows:

  1. Click on the Windows icon on the taskbar and search environment variable. Click open for the option listed as Edit the system environment variables.
edit the system environment variables
  1. The System Properties window will open. Select the Advanced tab and then Environment Variables…
system properties
  1. In the Environment Variables window, under System variables, select Path, then Edit…
environment variables
  1. Search the list for C:Program Filesnodejs. If this path doesn’t exist, you need to create a new one.
edit environment variable
  1. Click New…, then input a Variable name. For the Variable value enter “C:Program Filesnodejs“. Now click OK

3. Update Node.js

Outdated versions of Node.js can cause serious issues. To upgrade Node to the latest version:

  1. Right-click on the Windows icon on the taskbar. Select Windows PowerShell (Admin).
  2. 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
  3. After any packages install and update, check your version of Node.js to ensure it’s updated by entering “node -v“.

Linux Operating System

There are many Linux distributions available, but for the purpose of simplicity, this article will focus on solutions for Ubuntu. Ubuntu boasts the largest Linux distribution market share and has been around since 2004. Other popular distributions include Manjaro, Linux Mint, and Red Hat, but much of the solutions will be applicable to these distributions as well. The solutions are specifically for Ubuntu 20.04.

Below are four solutions to solve the ‘npm command not found’ error on Ubuntu:

1. Install Node.js and npm

Installing Node.js and npm on Ubuntu is fairly simple:

  1. Open a terminal window pressing CTRL+ALT+T simultaneously. Alternatively you can navigate to the Activities menu and search terminal, then clicking on the resulting icon for terminal.
  2. Type the following commands:
    • sudo apt update
    • sudo apt install nodejs npm
  3. When the packages are finished installing, you can verify that both Node.js and npm are installed by entering:
    • node –version
    • npm –version

In this solution, the sudo command gives the user elevated permissions (the same as an administrator). Now that Node.js and npm have been installed and verified, you can attempt to run an npm command.

2. Check PATH and system variables

You now know that npm is correctly installed on your system. Next we will verify the default path for the npm command:

  1. Open a terminal window pressing CTRL+ALT+T simultaneously. Alternatively you can navigate to the Activities menu and search terminal, then click on the resulting icon for terminal.
  2. To check the current path for npm commands enter “which npm“.
  3. The /etc/environment file needs to be checked for the file path from above, which may look something like /usr/bin/npm. Enter “cat /etc/environment“.
  4. This will give you a readout of your environment variable. You want to find the same file path from step 2, in your environmental variable. If not, continue on to add the npm path.
  5. To edit the /etc/environment file enter “vi /etc/environment“.
  6. Now you need to add a colon(:) and the npm path from step 2 to the end of the environmental file. This path file should end at ‘bin’. Make sure this path is before the end of the quotes.
  7. Enter “source /etc/environment” to reload the file with the changes.

3. Give User Permissions to Run Commands

Linux has been designed to be a secure operating system, because most applications have very limited permissions. Sometimes this can cause interference with how programs work. To give yourself permissions to edit node modules (where npm is located):

  1. Open a terminal window pressing CTRL+ALT+T simultaneously. Alternatively you can navigate to the Activities menu and search terminal, then click on the resulting icon for terminal.
  2. Enter “sudo chown -R $(whoami):admin /usr/local/lib/node_modules/“.
  3. Attempt to run an npm command and see if the problem reoccurs.

4. Update Node.js

Finally, older outdated versions of Node.js can cause version issues. To upgrade Node to the latest version, you will use npm:

  1. Open a terminal window pressing CTRL+ALT+T simultaneously. Alternatively you can navigate to the Activities menu and search terminal, then click on the resulting icon for terminal.
  2. Enter “sudo npm cache clean -f” to clear your current cache so that there are no problems accessing the correct file path, if you changed it in the second solution.
  3. Now enter “sudo npm install npm@latest -g“.
  4. You can verify that Node updated to the latest version by entering “npm -v“.

MacOS

1. Install Node.js and npm

Homebrew is a highly popular package manager for MacOS. If you have Homebrew installed on your Mac computer, it is very easy to install Node.js. You should strongly consider downloading Homebrew if you don’t have it. This solution will show you how to install Homebrew, as well as Node.js and npm:

  1. Click the Launchpad icon in the Dock, then search for Terminal. Click the result for Terminal.
  2. Type in the following command into your Terminal window to install Homebrew:
    • /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
  3. Then enter:
    • brew update
    • brew install node
  4. To verify that both are installed, enter “node -v” and “npm -v” to confirm the version of both Node.js and npm.
  5. Check if the ‘npm command not found’ error remains.

Alternatively you can find and use the Node.js installer for macOS.

2. Check PATH and system variables

For macOS, npm is usually found under /usr/local/bin. To check your PATH variable:

  1. Click the Launchpad icon in the Dock, then search for Terminal. Click the result for Terminal.
  2. Into the terminal enter echo $PATH, to display your PATH variable.
  3. Now enter “npm get prefix“. Compare the two outputs. Most likely the npm get prefix command will report /usr/local/bin. This should also be found in your PATH variable.
  4. If the prefix is NOT found in the PATH variable, it needs to be set. To set your PATH enter “export PATH=”[prefix]/bin:$PATH” >> ~/.bash_profile“. [prefix] is the value returned in step 3. Now enter “source ~/.bash_profile“.
  5. Check to see if the ‘npm command not found’ error is now resolved by trying the same command that failed previously.

3. Give User Permissions to Run Commands

MacOS shares a lot of similarities with Linux. Like Linux, you may need to give yourself permissions to edit node modules to bypass this error:

  1. Click the Launchpad icon in the Dock, then search for Terminal. Click the result for Terminal.
  2. Enter “sudo chown -R $(whoami):admin /usr/local/lib/node_modules/“.
  3. Attempt to run an npm command and see if the problem reoccurs.

4. Update Node.js and npm

If you installed Homebrew from the first MacOS solution, this will be extremely simple. If you don’t have Homebrew or another package manager like Nvm or N, you need to visit the Node.js website to find the newest installer for the updated version. Make sure to follow the default installation settings and don’t choose custom install unless you know what you are doing.

  1. If you have Homebrew, click the Launchpad icon in the Dock, then search for Terminal. Click the result for Terminal.
  2. Enter “brew upgrade node“.
  3. That’s it! Double-check by entering “node -v” and “npm -v” to ensure you are up-to-date.

Key Takeaway

The ‘npm command not found’ can be a major pain when you are working to develop an application and can’t access an important directory like npm. Without npm you don’t have access to the libraries for Node.js, and will spend significant extra time coding simple and common features by hand.

This article was broken down into three major sections for the operating systems Windows, Linux, and MacOS. This was to allow you easy access to solutions that would be helpful for your system, without requiring you to wade through non-useful information.

The four primary causes of the ‘npm command not found’ error are Node.js and/or npm not installed, path and system variables not set properly, outdated Node.js, and permissions conflicts. The solutions across all three operating systems are fairly simple and straightforward. If you were not familiar with command line (terminal, bash, etc) commands, you may have learned some useful commands in these solutions. Let us know in the comments section which solution worked, or if we have left out anything!

Понравилась статья? Поделить с друзьями:
  • Sudo apt get update error
  • Sudo a2enmod php error module php does not exist
  • Sudeki как изменить разрешение
  • Sudden changes in the reducer temperature indications гбо ошибка
  • Sud error samsung