linux上安装pm2(解决pm2: command not found问题)

责编:menVScode 2019-05-20 11:04 阅读(215)

1. 首先安装好node环境,输入安装pm2命令

npm install pm2 -g

点击回车键后:

/home/node10.8.0/bin/pm2 -> /home/node10.8.0/lib/node_modules/pm2/bin/pm2
/home/node10.8.0/bin/pm2-dev -> /home/node10.8.0/lib/node_modules/pm2/bin/pm2-dev
/home/node10.8.0/bin/pm2-docker -> /home/node10.8.0/lib/node_modules/pm2/bin/pm2-docker
/home/node10.8.0/bin/pm2-runtime -> /home/node10.8.0/lib/node_modules/pm2/bin/pm2-runtime
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/pm2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ pm2@3.5.0
updated 1 package in 32.548s


   ╭───────────────────────────────────────────────────────────────╮
   │                                                               │
   │       New minor version of npm available! 6.2.06.9.0       │
   │   Changelog: https://github.com/npm/cli/releases/tag/v6.9.0   │
   │               Run npm install -g npm to update!               │
   │                                                               │
   ╰───────────────────────────────────────────────────────────────╯


2. 测试pm2有没有安装成功,输入 【pm2 list】 显示:

-bash: pm2: command not found

说明pm2没有配制到全局,虽然安装到全局,但linux下不像windows下能自动创造一个环境变量去实现我们的全局,因此需要手动创建一个linux下的软连接。


3. 创建pm2软连接

3.1 找到全局环境PATH路径,输入命令【echo $PATH】,按回车键

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

可能你的路径和我的不一样,不过没关系,你可以选择任何一个以:隔开的路径做为系统环境路径,通常我们会选/usr/local/bin,node和npm的软连接也是在这个目录下。

3.2 找到pm2的安装路径

在安装pm2成功后,会显示他的安装路劲。从上面的安装结果,我能找到pm2的安装路劲:

/home/node10.8.0/bin/pm2

3.3 软连接命令执行

ln -s /home/node10.8.0/bin/pm2 /usr/local/bin

3.4 测试pm2有没有安装成功

[root@bigstudednt web]# pm2 list

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

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


                          Runtime Edition

        PM2 is a 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/
标签: linux pm2
前端交流群: MVC前端网(menvscode.com)-qq交流群:551903636

邮箱快速注册

忘记密码