The shell cannot find pm2 after you installed it
pm2: command not foundShort answer
The shell found no pm2 file in any folder of PATH. Either PM2 was never installed globally, or npm put it in a bin folder PATH does not include, often under a version manager or inside a non-login shell like CI. Ask npm for its prefix and add its bin folder.
Fix it fast
1Find out which cause you have
Ask npm where global packages go, and whether pm2 is there.
npm config get prefix ls "$(npm config get prefix)/bin" | grep pm2 echo "$PATH"2Match what you see, then jump to its fix
- 1
No pm2 file in the npm prefix bin folder.PM2 was not installed globallyFix - 2
pm2 exists in the prefix bin folder but the shell cannot find it.npm's global bin folder is not on PATHFix - 3
pm2 works when you log in but fails in GitHub Actions or a remote command.A CI or SSH shell does not load your profileFix
- 1
What does the error look like?
pm2: command not foundbash: pm2: command not found
Cause 1 of 3
PM2 was not installed globally
1Check
A local install in a project puts it under node_modules/.bin, which is not on PATH.
npm ls -g --depth=02Fix
Install it globally.
npm install pm2@latest -g3Verify
The command resolves.
pm2 --versionConfirmed by pm2.keymetrics.io
Cause 2 of 3
npm's global bin folder is not on PATH
1Check
After changing npm's prefix, the bin folder must be added to PATH in your profile.
npm config get prefix
echo "$PATH" | tr ':' '\n'2Fix
Set a prefix you own and add its bin folder to PATH, then reload the profile.
npm config set prefix ~/.local
echo 'PATH=~/.local/bin:$PATH' >> ~/.profile
source ~/.profile3Verify
Reinstall and run it.
npm install -g pm2
pm2 --versionConfirmed by docs.npmjs.com
Cause 3 of 3
A CI or SSH shell does not load your profile
1Check
A non-interactive shell skips the profile where PATH was set, so a folder you added is missing.
ssh user@server 'echo $PATH; which pm2'2Fix
Put the bin folder in PATH inside the command itself, using the folder from npm's prefix.
ssh user@server 'export PATH="$HOME/.local/bin:$PATH"; pm2 reload all'3Verify
The remote command prints PM2 output rather than the error.
ssh user@server 'export PATH="$HOME/.local/bin:$PATH"; pm2 --version'Confirmed by gnu.org
How do I stop it coming back?
- Keep one Node install method on the server and reuse its path in deploy scripts.
- After install, run pm2 startup and pm2 save so processes return after a reboot.
- Print which pm2 early in a deploy job so a missing path fails fast.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
Related fixes
Servers
Azure App Service on Linux restarts the container and the site never starts
The container restarts again and again and the site returns an application error
App Service sends a warmup request to the container and restarts it if no HTTP answer comes back in time.
5 causes, each with a fixServers
nginx 502 Bad Gateway in front of a Node.js app
connect() failed (111: Connection refused) while connecting to upstream
A 502 means nginx reached for your Node.js app and got nothing usable back.
5 causes, each with a fixServers
apt-get does not exist on this EC2 instance
sudo: apt-get: command not found
apt-get belongs to Debian and Ubuntu.
2 causes, each with a fixServers
bash warns that it cannot change the locale after you log in to a server
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
The shell was told to use a locale that is not built on the server.
3 causes, each with a fixServers
Syntax error: redirection unexpected when a Bash script runs under sh
script.sh: 12: Syntax error: redirection unexpected
The operators <<< (here-string) and &> are Bash features.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fix