温馨提示×

Ubuntu Apache2怎么卸载

小樊
46
2026-09-20 13:01:12
栏目: 智能运维

在 Ubuntu 上卸载 Apache2,可以按下面步骤操作,根据你是否需要彻底清除来选择。


一、停止 Apache 服务

sudo systemctl stop apache2

二、卸载 Apache2

1️⃣ 普通卸载(保留配置文件)

sudo apt remove apache2

2️⃣ 完全卸载(推荐,删除配置)

sudo apt purge apache2

三、删除依赖和残留文件(可选但推荐)

sudo apt autoremove

清理可能残留的目录:

sudo rm -rf /etc/apache2
sudo rm -rf /var/www/html
sudo rm -rf /var/log/apache2

四、确认是否已卸载

which apache2
systemctl status apache2

如果显示 command not foundUnit apache2.service could not be found,说明已卸载成功。


五、如果你是用 tasksel 安装的(LAMP)

有时 Apache 是通过 LAMP 套件安装的,可额外检查:

sudo apt purge apache2 apache2-utils apache2-bin apache2.2-common

如果你之后打算 重装 / 换 Nginx / 用 Docker,也可以告诉我,我可以给你对应方案。

0