How to Fix 'bash: npm: command not found' After Installing Node.js
In this tutorial, you'll learn about How to Fix 'bash: npm: command not found' After Installing Node.js. We cover key concepts, practical examples, and best practices.
The Problem
You just installed Node.js but typing npm --version returns:
bash: npm: command not found
Why this happens after installation
npm is bundled with Node.js, but the shell may not find it after installation. Common causes: the terminal was opened before installation and still has an old PATH, the installer did not add Node to PATH, or the installation did not complete correctly. Sometimes node --version works while npm does not — this means the npm binary is missing or in a different directory.
Run these two commands to diagnose:
node --version
which npm
If node works but which npm returns nothing, npm was not installed or is in an unusual location.
Quick Fix
1. Restart your terminal
Close and reopen your terminal, or reload your shell config:
source ~/.bashrc
# or
source ~/.zshrc
This often works because the installer modifies your shell config to add Node to PATH, but the new PATH only takes effect when the shell starts. Running source reloads the config without closing the terminal.
2. Check if Node.js is installed
node --version
If Node works but npm doesn't:
# Check where Node is
which node
# /usr/local/bin/node
# Check if npm is in the same directory
ls /usr/local/bin/npm
If node --version works, Node.js is installed. which node shows where it lives. Check if npm is in the same directory. If missing, the installation did not include npm and you need to reinstall.
3. Reinstall Node.js (includes npm)
Using NodeSource (Linux):
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs
Using nvm:
nvm install --lts
nvm use --lts
The NodeSource method gives you a system-wide installation managed by apt. The nvm method installs in your home directory and avoids permission issues. Choose the method that matches how you originally installed Node.js — switching methods can cause conflicts.
4. Add npm to PATH manually
export PATH="/usr/local/bin:$PATH"
If using nvm:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Add to ~/.bashrc or ~/.zshrc for permanence.
The first command adds /usr/local/bin to the front of your PATH, making it the first directory searched when you type a command. The nvm block loads the nvm initialization script, which adds npm to PATH and sets up shell integration. Add the relevant block to your shell config file to make the fix permanent.
Install npm Standalone
# Reinstall just npm
sudo apt install npm
Or use the npm standalone installer:
curl -qL https://www.npmjs.com/install.sh | sh
These are fallback options. Installing npm separately from Node.js can lead to version mismatches. Only use these if reinstalling Node.js is not practical. After running the standalone installer, verify with npm --version and check that the version is compatible with your Node.js version using the official compatibility table.
Prevention
Use a version manager. nvm (Node Version Manager) installs Node.js and npm in your home directory, avoiding PATH issues and permission problems entirely. It also makes switching between Node.js versions trivial.
Always restart your terminal after installation. Even if the installer says "installation complete," the current terminal session still has the old PATH. Make a habit of opening a new terminal window after any installation.
Verify both Node and npm after installation. Run node --version && npm --version immediately after installing. If npm is missing, fix it right away while the installation steps are still fresh.
Use the LTS release. The Current release of Node.js sometimes has npm compatibility issues. The LTS (Long Term Support) release is more stable and tested more thoroughly.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro