Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash: pm2: command not found

I can't run pm2 on ubuntu box. I'm not sure what's the problem. The pm2 is installed globally.

npm list -g --depth=0
/opt/nodejs/lib
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

But I still get

pm2
-bash: pm2: command not found

if I run other app

userdown
Starting Script is not provided

versions

node v4.5.0
npm  v2.15.9

log from installation:

sudo npm install pm2 -g
npm WARN optional dep failed, continuing [email protected]
/opt/nodejs/bin/pm2 -> /opt/nodejs/lib/node_modules/pm2/bin/pm2
/opt/nodejs/bin/rundev -> /opt/nodejs/lib/node_modules/pm2/bin/rundev
/opt/nodejs/bin/pm2-dev -> /opt/nodejs/lib/node_modules/pm2/bin/pm2-dev
/opt/nodejs/bin/pm2-docker -> /opt/nodejs/lib/node_modules/pm2/bin/pm2-docker
[email protected] /opt/nodejs/lib/node_modules/pm2
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected])
└── [email protected]
kamil@vps2:~$ pm2
-bash: pm2: command not found

ubuntu version:

uname -a
Linux vps2 2.6.32-042stab111.11 #1 SMP Tue Sep 1 18:19:12 MSK 2015 x86_64 x86_64 x86_64 GNU/Linux
like image 364
Kamil Avatar asked Nov 25 '16 07:11

Kamil


People also ask

Does pm2 need to be installed globally?

yes, you need to install it globally.


2 Answers

Ok got answer myself. I check what happens for

whereis pm2
pm2: /opt/nodejs/bin/pm2

then I checked

whereis userdown
userdown: /usr/bin/userdown /usr/bin/X11/userdown /opt/nodejs/bin/userdown

hmm in /usr/bin.... So I did

sudo ln -s /opt/nodejs/bin/pm2 /usr/bin/pm2 

and it works :)

like image 115
Kamil Avatar answered Oct 21 '22 21:10

Kamil


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 -gflag 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
like image 34
Luís Brito Avatar answered Oct 21 '22 20:10

Luís Brito