ubuntu中如何查看是否已经安装了nginx

319 阅读1分钟

在 Ubuntu 系统中,可以通过以下几种方法检查是否已安装 Nginx


方法 1:使用 dpkg 命令(适用于 Debian/Ubuntu)

bash
dpkg -l | grep nginx
  • 输出示例

    ii  nginx                       1.18.0-0ubuntu1   all          small, powerful, scalable web/proxy server
    ii  nginx-common                1.18.0-0ubuntu1   all          small, powerful, scalable web/proxy server - common files
    
  • 说明

    • 如果已安装,会显示 Nginx 的版本和状态(ii 表示已安装且正常)。
    • 如果未安装,无输出或提示 No packages found matching nginx

方法 2:检查 Nginx 服务状态

bash
systemctl status nginx

或(旧版 Ubuntu 使用 service 命令):

bash
service nginx status
  • 输出说明

    • 已安装:显示服务状态(active (running) 或 inactive (dead))。
    • 未安装:提示 Unit nginx.service not found 或 nginx: unrecognized service

方法 3:直接运行 nginx 命令

bash
nginx -v

或查看详细版本信息:

bash
nginx -V
  • 输出说明

    • 已安装:显示版本号(如 nginx version: nginx/1.18.0)。
    • 未安装:提示 Command 'nginx' not found