1

I am installing PM2 for hubot rocket.chat adapter. so i did the following: I firstly added a file to hubot adapter folder, then

sudo npm install pm2 -g
cd <hubot directory>
pm2 start <pm2.json>

The i got error saying this:

No command 'pm2' found, did you mean:
 Command 'wm2' from package 'wm2' (universe)
 Command 'pms' from package 'pms' (universe)
 Command 'pmk' from package 'pmk' (universe)
 Command 'pmw' from package 'pmw' (universe)
 Command 'fpm2' from package 'fpm2' (universe)
 Command 'pom2' from package 'libpod-pom-perl' (universe)
 Command 'pmi' from package 'powermanagement-interface' (universe)
 Command 'pm' from package 'powerman' (universe)
pm2: command not found

Then I tried to add the path by doing:

sudo env PATH=$PATH:/home/jy/.npm-global/bin pm2 startup -u safeuser

and

export PATH=$PATH:/home/jy/.npm-global/bin

and restarted PuTTY,

still get the same error.

when I went to where PM2 is at, which is /home/jy/.npm-global/bin, and do pm2 start <pm2.json> command, still get the same error.

Is there anything i did wrong? or there might be other reasons?

EJ2017
  • 11
  • 1
  • 2
  • 4

1 Answers1

0

The problem is that you are running NPM as sudo, so you will only be able to access it using:

sudo pm2 start server.js

Install without sudo, you may even install without the -g flag and call it directly from node_modules directory. This may be useful if you do not have root (admin) privileges in the machine you're working on.

npm install pm2
./node_modules/.bin/pm2 start server.js


Source: https://stackoverflow.com/a/40812333/1052581

Community
  • 1
  • 1
Luís Brito
  • 1,652
  • 1
  • 17
  • 34