pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

install pm2 for all user.

Open alicera opened this issue 2 years ago • 8 comments

how to install pm2 for all user.

There are two user "dev and gen"

how to install pm2 with user dev? and the user gen can direct use pm2

alicera avatar Oct 20 '22 04:10 alicera

I solved it by installing pm2 and then make an alias which runs it as one user

alias pm2='sudo -u node /usr/bin/pm2'

which i put in an shell configuration file everybody read for example /etc/profile.d/pm2.sh

johandalabacka avatar Oct 28 '22 09:10 johandalabacka

how do you installing pm2?

In fact, I want to let all user use "one pm2" So, the process that pm2 list should be the same process.

alicera avatar Oct 29 '22 12:10 alicera

I install it with sudo rpm -g i pm2 so it gets globally installed. I then have one account node who nobody uses directly it is only used to run pm2. The alias I mentioned above runs pm2 as the user node (-u node). So writing pm2 list is really sudo -u node /usr/bin/pm2 list You don't have to name the account node. It could be anything.

johandalabacka avatar Oct 30 '22 17:10 johandalabacka

Hi @johandalabacka Thanks for your reply

I use this to install pm2 It will generate /home/"$USER"/.pm2 Where is the rpm generate

npm install -g pm2

by the way, I use npn install pm2 and the nvm is install on /home/"$USER"/.nvm Does it cause the the pm2 install on /home/"$USER"/.nvm/*//pm2 ?

alicera avatar Nov 02 '22 07:11 alicera

Hi. Is this on a production server? maybe you shouldn't use nvm or at least read up on using nvm in a multiuser enviroment. We install node as a package on our server so all globally installed packages are put in the same folder and not in someones library.

johandalabacka avatar Nov 02 '22 07:11 johandalabacka

I just follow the step https://www.makeuseof.com/how-to-install-and-set-up-pm2-on-linux-servers/ to install nvm and pm2. Then they are put in someones library.

Do you have the the script to install node ? I appreciate your help very much.

We install node as a package on our server so all globally installed packages are put in the same folder

alicera avatar Nov 02 '22 11:11 alicera

hi @alicera, for installing node, i would also suggest nvm,

installing nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash exit and start the terminal again

install lts version of the node

nvm install --lts

using node's latest version

nvm use lts/*

installing pm2

npm i -g pm2

getting pm2 path

which pm2

using command suggested by @johandalabacka

alias pm2='sudo -u node /usr/bin/pm2'

in place of /usr/bin/pm2 put the path you get using which command

thanks

itsvinayak avatar Dec 09 '22 18:12 itsvinayak

Using the root user, install the PM2 library globally. Create the necessary users and execute this command.

n=$(which pm2);n=${n%/bin/pm2}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local

IhorReactNative avatar Apr 14 '24 08:04 IhorReactNative