PM2 command not found

October 17, 2016 85 views
Applications Ubuntu

I am installing PM2 for hubot adapter. so i did the following:
I firstly added a <pm2.json> 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
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?

2 Answers

Did you tried executing it as root?

  • sudo pm2 status

Maybe you can try installing it as non-root user (your current user if you don't use root). For that you need to enable global installing for non-root users by fixing permissions. There is Fix permissions tutorial on NPM docs page which should help you with it

  • I tried both from home directory and bin directory, where i believe pm2 is at, all got sudo: pm2: command not found. pls see following:

    jy@ubuntu-1gb-sfo2-01:~$ sudo pm2 list
    sudo: pm2: command not found


    jy@ubuntu-1gb-sfo2-01:~$ cd /home/jy/.npm-global/bin
    jy@ubuntu-1gb-sfo2-01:~/.npm-global/bin$ sudo pm2 list
    sudo: pm2: command not found

    also i noticed that under /home/jy/.npm-global/bin, there are folders pm2, pm2-dev, pm2-docker, none of those can be opened by jy, SFTP says :

    Error: directory /home/jy/.npm-global/bin/pm2: no such file or directory
    Error: Failed to retrieve directory listing

    and permissions of these folders shows as Irwxrwxrwx, owner shows as root root.
    I tried run as root doing both as above, still the same.

    I previously installed as non-root user and installed it globally

    what might be wrong?

    • Hi again,

      You should try adding prefix/bin in your PATH. Prefix/bin is location where npm does install binaries for global packages.
      We will use npm to get prefix.

      • npm get prefix

      This will return you prefix location.

      Sample output

      Now open your .bashrc with favorite text editor and add it to path.

      • nano ~/.bashrc

      If you already have export PATH=..., add to the end of it: :prefix you got/bin.
      If you don't have it, add anywhere line : export PATH=$PATH:prefix/bin.

      Save it, exit editor and source file or log out/log in.

      • source ~/.bashrc

      You can verify does you have it in PATH by running echo $PATH. At end of it you should see new path you added.
      If it is OK, try running pm2 again and hope for best :)

Have another answer? Share your knowledge.