温馨提示×

Debian怎样卸载nginx软件

小樊
44
2026-09-12 11:04:35
栏目: 智能运维

在 Debian 系统中,卸载 nginx 通常有以下几种方式,根据你安装方式不同略有区别。下面按常见情况说明。


一、使用 apt 安装的 nginx(最常见)

1️⃣ 停止 nginx 服务

sudo systemctl stop nginx
sudo systemctl disable nginx

2️⃣ 卸载 nginx 软件包

sudo apt remove nginx nginx-common nginx-full

如果你不确定装了哪些 nginx 包,可以先查:

dpkg -l | grep nginx

3️⃣ 彻底卸载(删除配置和依赖)

sudo apt purge nginx nginx-common nginx-full

4️⃣ 删除无用依赖

sudo apt autoremove

5️⃣ 手动删除残留配置(可选)

sudo rm -rf /etc/nginx
sudo rm -rf /var/log/nginx
sudo rm -rf /var/www/html(如不需要)

二、源码编译安装的 nginx

如果是 make && make install 安装的:

1️⃣ 停止 nginx

sudo nginx -s stop

2️⃣ 删除安装目录(常见位置)

sudo rm -rf /usr/local/nginx

3️⃣ 删除环境变量(如有)

sudo rm /usr/local/bin/nginx

并检查:

nano ~/.bashrc
# 或
nano /etc/profile

三、验证是否卸载成功

nginx -v

若提示 command not found 说明已卸载。


四、常见注意事项

  • purge 会删除配置文件,生产环境谨慎
  • 若使用 docker / snap 安装的 nginx,卸载方式不同
  • 卸载前建议备份 /etc/nginx

如果你是 具体某种安装方式(apt / 源码 / docker),可以告诉我,我可以给你更精确的命令。

0