Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

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


Last Updated : 25 May, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads