Pm2: Local install?

Created on 19 Jul 2017  路  9Comments  路  Source: Unitech/pm2

Is this possible? I'd prefer not to install globally. This should be possible.

I'm currently getting this error when trying npx pm2 --help and/or node_modules/.bin/pm2 --help:

Error: connect EACCES /Users/username/.pm2/rpc.sock

on OSX 10.12.5

Most helpful comment

It's magically working now, directly and indirectly. All I did was sudo rm ~/.pm2/rpc.sock and reinstalled pm2. I don't get it.

All 9 comments

It is possible: npm install pm2 --save will install pm2 to node_modules and package.json.
The pm2 CLI will be symlinked in node_modules/.bin.

By default, pm2 spawns a persistent daemon process, and regardless of whether pm2 is installed globally or locally, it will still create the working directory ~/.pm2 for whichever user launches the daemon.

Looks like npx is some sort of wrapper around npm.
What happens if you just run pm2 directly, like node_modules/.bin/pm2 --help?

npx ships with npm@5

node_modules/.bin/pm2 --help throws the same error

Ah ok, looks like npx was recently introduced with [email protected]. Maybe pm2 has not been tested with this tool yet.

But your issue seems to be permission related.
Is the pm2 daemon running i.e. what is the output of ps -eo user,pid,command | grep pm2?
Can you try rm -fr /Users/username/.pm2 && npx pm2 kill?

I believe you can control where the .pm2 working directory is located by exporting PM2_HOME before issuing a pm2 command, e.g. export PM2_HOME=/with/write/permission/.pm2 && pm2 start script.js

Indeed, it's working under Ubuntu 16.04 so you might just not have the permission to write/read from ~/.pm2/

@dalgleish the first command only listed the grep and the second resulted in the same error as above.

@vmarchaud but I do have such permissions for that path. Why would you close this so abruptly?

@stevenvachon please do not take personally the fact that i'm closing this issue, i just closed it because PM2 just return error he got from the system, in this case he doesn't have access to a file so you must have a reconfiguration somewhere.
Anyway, i don't get the point of running pm2 with npx ? If i understand npx is used to launch binary but PM2 is already a CLI so it doesn't need it

npx is easier than typing node_modules/.bin/pm2. Once it works without error, I'll put it in my npm start script.

It's magically working now, directly and indirectly. All I did was sudo rm ~/.pm2/rpc.sock and reinstalled pm2. I don't get it.

@stevenvachon you probably did a sudo npx pm2 at some point and that made it only writable by root.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FujiHaruka picture FujiHaruka  路  3Comments

alexpts picture alexpts  路  3Comments

liujb picture liujb  路  3Comments

phra picture phra  路  3Comments

psparago picture psparago  路  3Comments