安装Apache时出错;错误是“E:子进程/usr/bin/dpkg返回了错误代码(1)”

Siv*_*nan 3 ubuntu dpkg apt apache-httpd

我按照在线文章 从我的系统中删除了我的 Apache
我通过这些命令删除了 Apache

sudo apt-get purge apache2 apache2-utils
sudo rm -rf /etc/apache2-bin
sudo apt-get autoremove
Run Code Online (Sandbox Code Playgroud)

然后在文章中他们提到删除whereis apache2.

运行命令后whereis apache2我发现

/usr/sbin/apache2/usr/share/apache2
/usr/lib/apache2
/usr/share/man/man8/apache2.8.gz
/etc/apache2
Run Code Online (Sandbox Code Playgroud)

我通过命令删除了上述目录和文件sudo rm -rf file_or_directory_name

然后我试过了

sudo apt-get install apache2
Run Code Online (Sandbox Code Playgroud)

当系统询问时,我点击了“y”do you want to continue?

然后错误来了:

Setting up apache2 (2.4.7-1ubuntu4.4) ...
cp: cannot stat ‘/usr/share/apache2/default-site/index.html’: No such file or directory
dpkg: error processing package apache2 (--configure): subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:  apache2 E: Sub-process /usr/bin/dpkg returned an error code (1)
Run Code Online (Sandbox Code Playgroud)

sudo apt-get install apache2运行sudo apt-get update命令后我再次尝试,但仍然得到相同的错误结果。

Ste*_*itt 5

要恢复,/usr/share/apache2/default-site/index.html您需要重新安装apache2-data. 鉴于您目前的情况,请尝试

sudo apt-get purge apache2-data
sudo apt-get install apache2
Run Code Online (Sandbox Code Playgroud)

大概你的系统最终处于那种状态,因为apt-get autoremove没有卸载apache2-data,但你rm -rf删除了它包含的文件。然后apt-get install apache2会认为它apache2-data仍然安装并且不需要重新安装,但是它的文件消失了......