Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

The shell cannot find pm2 after you installed it

Errorpm2: command not found

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

  • Applies to PM2 5, Node.js 22, npm 10, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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"
  2. 2Match what you see, then jump to its fix

    1. 1No pm2 file in the npm prefix bin folder.PM2 was not installed globallyFix
    2. 2pm2 exists in the prefix bin folder but the shell cannot find it.npm's global bin folder is not on PATHFix
    3. 3pm2 works when you log in but fails in GitHub Actions or a remote command.A CI or SSH shell does not load your profileFix

What does the error look like?

  • pm2: command not found
  • bash: 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=0

2Fix

Install it globally.

npm install pm2@latest -g

3Verify

The command resolves.

pm2 --version

Confirmed by pm2.keymetrics.io

Did this fix it?

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 ~/.profile

3Verify

Reinstall and run it.

npm install -g pm2
pm2 --version

Confirmed by docs.npmjs.com

Did this fix it?

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

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.