Install pm2 under linux, pm2: command not found

For a linux novice, it is really a big pit. I have seen many examples on the Internet, but none of them can explain it clearly. I found that no program dog can describe a problem as perfectly as me. If you don't agree to kill me, I won't fight back.

1: Install pm2

Operation description:

       There are many ways to install pm2 on linux, but I use node's tool npm to complete the installation, so you need to install node before installing pm2. If not here, just install node on Baidu. I won't do this trivial matter. If you don't agree, you can add.

Theme:

Enter the command in any directory of yours:   npm install pm2 -g 

[root@VM_165_102_centos /]# npm install pm2 -g

After returning...

/usr/local/node-v8.9.3-linux-x64/bin/pm2 -> /usr/local/node-v8.9.3-linux-x64/lib/node_modules/pm2/bin/pm2
/usr/local/node-v8.9.3-linux-x64/bin/pm2-dev -> /usr/local/node-v8.9.3-linux-x64/lib/node_modules/pm2/bin/pm2-v
/usr/local/node-v8.9.3-linux-x64/bin/pm2-docker -> /usr/local/node-v8.9.3-linux-x64/lib/node_modules/pm2/bin/p-docker
/usr/local/node-v8.9.3-linux-x64/bin/pm2-runtime -> /usr/local/node-v8.9.3-linux-x64/lib/node_modules/pm2/bin/2-runtime
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/pm2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","ch":"any"} (current: {"os":"linux","arch":"x64"})

+ [email protected]
added 221 packages from 206 contributors in 29.63s

There are several warns regardless of him, because in the code world, warns are nothing, as long as there are no errors.

After the installation is complete, you execute the command:   pm2 list  

[root@VM_165_102_centos /]# pm2 list

After carriage return:

-bash: pm2: command not found

Explanation, it is not configured globally. Although it is installed globally, I don't know why it is gross. Unlike Windows, it can automatically create an environment variable to realize our global. So we need to create a soft connection under linux.

2: Create a soft link

Operation description: The setting of soft connection on linux is equivalent to the configuration of environment variables under windows, but the operation is done by command here. Here we start to create a soft connection for pm2. The first thing to be clear here is that we need to know who is connecting with whom. What is the problem? Do you know which is connected to which? Well, the answer is: our global $PATH under linux and our pm2 installation path. So how do we know where their paths are?

a: Find the global environment PATH path

Enter the command: echo $PATH  

[root@VM_165_102_centos /]# echo $PATH

After returning...

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

Explanation, your path is not the same as mine, but it doesn't matter, you can choose any path separated by: as the system environment path, I usually choose /usr/local/bin

b: Find the installation path of pm2

Usually when we install pm2, there will be an installation path displayed, the following code

So, this is your pm2 installation path: /usr/local/node-v8.9.3-linux-x64/bin/pm2

Maybe it will be different, but you can see it here. If not, you can use whereis or find command to find.

Well, all found, the important step is to start, open your eyes.

The command is:   ln -s /usr/local/node-v8.9.3-linux-x64/bin/pm2 /usr/local/bin/  

[root@VM_165_102_centos /]# ln -s /usr/local/node-v8.9.3-linux-x64/bin/pm2 /usr/local/bin/

OK, it's done, let's verify it next...

The command is: [root@VM_165_102_centos /]# pm2 list

[root@VM_165_102_centos /]# pm2 list

After returning...

[root@VM_165_102_centos /]# pm2 list

                        -------------

__/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____
 _\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___
  _\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__
   _\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___
    _\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____
     _\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________
      _\/\\\_____________\/\\\_____________\/\\\___/\\\/___________
       _\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_
        _\///______________\///______________\///__\///////////////__


                          Community Edition

            Production Process Manager for Node.js applications
                     with a built-in Load Balancer.


                Start and Daemonize any application:
                $ pm2 start app.js

                Load Balance 4 instances of api.js:
                $ pm2 start api.js -i 4

                Monitor in production:
                $ pm2 monitor

                Make pm2 auto-boot at server restart:
                $ pm2 startup

                To go further checkout:
                http://pm2.io/


                        -------------

[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
┌──────────┬────┬──────┬─────┬────────┬─────────┬────────┬─────┬─────┬──────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
└──────────┴────┴──────┴─────┴────────┴─────────┴────────┴─────┴─────┴──────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app

It means that the installation is successful and pm2 can be accessed anywhere

If you do not succeed, please leave a message and discuss together.

THE END!!!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325344381&siteId=291194637