43

I recently was messing around with my Apache config and wanted to reinstall so I could start from fresh. I followed some forum posts about reinstalling the apache2 package and this ended up deleting my /etc/apache2 folder.

Now matter how many things I try I can't seem to do a full wipe of the Apache install and then reinstall. sudo apt-get install apache2 or reinstall doesn't do anything. I can't seem to remove it using Synaptic either.

Is there anything I can do to have a fresh Apache install on my computer again?

lofidevops
  • 20,924
seadowg
  • 565
  • 1
    /etc/apache2/envvars is in apache2.2-common, have you reinstalled that package too? Like with command sudo apt-get --reinstall install apache2.2-common – LGB Feb 14 '11 at 07:07

4 Answers4

82

To replace configuration files that have been deleted, without purging the package, you can do

sudo apt-get -o DPkg::Options::="--force-confmiss" --reinstall install apache2

To fully remove the apache2 config files, you should

sudo apt-get purge apache2

which will then let you reinstall it in the usual way with

sudo apt-get install apache2

Purge is required to remove all the config files - if you delete the config files but only remove the package, then this is remembered & missing config files are not reinstalled by default.

jmunsch
  • 2,213
  • 1
  • 22
  • 29
ajmitch
  • 18,543
  • This also doesn't work. It says that apache2 is already installed and the purge doesn't remove the config file in etc/apache2. In fact the purge complains that it can't envvars too. – seadowg Feb 14 '11 at 10:31
  • Has reinstalling apache2.2-common with the option about to replace missing conf files worked for you? – ajmitch Feb 17 '11 at 00:51
  • Almost a year later and found this, thank you very much. – nerdwaller Dec 06 '12 at 16:35
  • 1
    helped a lot, but package apache2.2-common doesn't exist anymore....did the same sequence just with package apache2 – Jürgen Zornig Jun 20 '14 at 07:20
  • Not tested with Ubuntu, but under Debian to restore config files which are managed by ucf the --force-confmiss option won't work, you have to use sudo UCF_FORCE_CONFFMISS=1 apt-get --reinstall install [pkgname]. – Skippy le Grand Gourou Feb 23 '15 at 18:07
  • apt-get purge apache2 works in Debian 8! – rustyx Oct 28 '15 at 10:38
  • It happened to me that I had the file but was empty. It's important that the file to recover doesn't exists so it's installed again. – Miguel Ortiz Jul 31 '18 at 14:16
6

run the following command first

sudo apt-get remove --purge apache2 apache2-utils

then run

sudo apt-get install apache2

it worked for me

N.N.
  • 18,219
edd
  • 77
2

Remove Apache2 files...

sudo apt-get remove --purge apache2*

Clean install

sudo apt-get --reinstall install apache2.2-common
sudo apt-get --reinstall install apache2
kiri
  • 28,246
  • 16
  • 81
  • 118
Fox
  • 49
  • 1
-1

try this

apt-get -f install

then run

sudo apt-get install apache2

Edit: or possibly

sudo apt-get purge apache2
sudo apt-get install apache2
fabricator4
  • 8,375
Ahmed
  • 15
  • 1