Problem: When I run "pm2 ls"
under ec2-user, it runs perfectly.
When I run "pm2 ls" after sudo -i
, it gives -bash: pm2: command not found.
for safety reasons, sudo typically runs under a different environment. for example, an administrator could configure sudo to use a secure PATH rather than inheriting the caller's PATH.
you have a few options:
--preserve-env
, e.g. sudo -E "PATH=$PATH" env
.lastly, you can reconsider if pm2 really needs root permissions.