Open In App

How To Fix: Sudo npm: Command not Found on Linux

Last Updated : 25 May, 2022
Like Article

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

Note: We must have git installed to build it from the source. 

Step 1: See all the available versions of NodeJs.

git ls-remote | 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


Step 3: Navigate to the repository using the following command.

cd node

Step 4: Now execute the following commands for configuration and installation. 


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.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads