If the Linux server is not connected to the Internet, the PM2 cannot be installed using the common NPM install method. In this case, you need to install the PM2 in offline mode.

Download Source Code

Visit pM2’s release page on Github to download Source code.zip

Two, local decompression, installation dependency, and compression

On the office PC, decompress Source code.zip downloaded in the previous step and run NPM install to install the dependency. After the dependency is complete, compress the entire directory into a ZIP file and upload it to the server. At this point, there are more node_modules to run on than the Source code.zip you downloaded from Github

Upload the server and decompress it

On the server, create a directory to store the compressed package, and then decompress it. My directory is /app/pm2

4. Grant execute permission to files in bin directory

chmod -R 755 /app/pm2/bin/*
Copy the code

5. Establish a soft link between PM2 and Node

ln -s /app/pm2/bin/pm2 /opt/node/bin/pm2
ln -s /app/pm2/bin/pm2-dev /opt/node/bin/pm2-dev
ln -s /app/pm2/bin/pm2-docker /opt/node/bin/pm2-docker
ln -s /app/pm2/bin/pm2-runtime /opt/node/bin/pm2-runtime
Copy the code

6. Set PATH and execute pM2 instruction globally

#Edit/etc/profile
vi /etc/profile

#Add the following code at the end
export PM2_HOME=/app/pm2
export PATH=$PATH:$PM2_HOME/bin

#Wq input! Exit the editor

#usesourceCommand to make the modification take effect
source /etc/profile

#useechoThe command checks that path is as expected
echo $PATH
Copy the code

After setting, run the pm2-version command

If so, the installation is successful.