How to Solve NPM Command Not Found Error in Bash
The Node Package Manager or npm
is a package manager for the JavaScript programming language. It is the default package manager for the Node.js runtime environment.
When you download a package using the npm
tool, you may sometimes get a command not found
error. This article explains how to install npm
and solve this error in Bash.
Solve npm: command not found
Error in Bash
You get the npm: command not found
error because the nodejs
and npm
are not correctly installed on your system. The rest of the article will explain different ways to download these tools.
The nodejs
and npm
can be installed on Linux distributions with the following commands.
Install nodejs
and npm
for Arch Linux.
sudo pacman -S nodejs npm
Install nodejs
and npm
for Ubuntu and Debian.
sudo apt-get install nodejs npm
Install nodejs
and npm
for CentOS and Fedora.
sudo dnf install npm
Besides these, the npm
tool and nodejs
can be installed manually.
Download the tar
file from https://nodejs.org/en/ and unzip it.
curl https://nodejs.org/dist/v17.6.0/node-v17.6.0-linux-x64.tar.xz -o node-v17.6.0-linux-x64.tar.xz
tar -xvf node-v17.6.0-linux-x64.tar.xz
Create a directory under the /usr/local/
.
sudo mkdir -p /usr/local/nodejs
Move node files under /usr/local/nodejs/
.
sudo mv node-v17.6.0-linux-x64/* /usr/local/nodejs/
Add /usr/local/nodejs/bin
directory to PATH
in .bashrc
file.
sudo nano ~/.bashrc
export PATH=$PATH:/usr/local/nodejs/bin
Reload the .bashrc
file.
source ~/.bashrc
Install the npm
.
curl -L https://npmjs.org/install.sh | sudo sh
You can successfully install the npm
tool by choosing the one that suits you best from these options. To check the installation, check the version of the tools.
node --version
npm --version
Now you can download the packages you want using the npm install package
command. After doing these, if you still get the error in your development environment, close the application and open it again.
Yahya Irmak has experience in full stack technologies such as Java, Spring Boot, JavaScript, CSS, HTML.
LinkedIn