How to reinstall a package using 'apt-get'?

It seems that my aptitude is somehow broken:

sudo aptitude update
0% [Working]Segmentation fault

dmesg
[223282.616599] aptitude[30972]: segfault at 67707f ip 7f954dcfae5d sp 7ffff5a5f950 error 4 in libapt-pkg-libc6.7-6.so.4.6.0[7f954dca5000+bd000]

So I would like to reinstall aptitude by using apt-get.

Unfortunately it seems apt-get doesn't have a reinstall option.

How could I get aptitude to work again?

It's possible that I found the root cause for aptitude's segfault. Here is how I can reproduce it:

  1. 'ssh' remote login into the Debian machine via Cygwin's rxvt terminal (from a Windows 7 64-bit German edition).
  2. Enlarge the rxvt window so that it spans across two monitors (yes, I have two monitors)
  3. Run aptitude update. Note: when I resize the rxvt terminal to normal then I don't have these segmentation faults!

$ man apt-get | grep reinsta -A2
       --reinstall
           Re-Install packages that are already installed and at the newest
           version. Configuration Item: APT::Get::ReInstall.

So, to use it to reinstall aptitude use:

sudo apt-get install --reinstall aptitude

You can reinstall a package with sudo apt-get install --reinstall packagename. This completely removes the package (but not the packages that depend on it), then reinstalls the package.

This can be convenient when the package has many reverse dependencies.


Sometimes you need to restore config files too! not just reinstall.

sudo apt-get install --reinstall xxxx

Reinstall the application, keeps the config files.

This could be helpful, but sometimes you need to start fresh, so what I use is this:

sudo dpkg -r xxxx //to remove that xxxx package
sudo dpkg -P xxxx //to purge all related files

then

sudo apt-get install xxxx

You should be safe to remove aptitude and reinstall, as that won't affect the other apt utilities. So: apt-get remove aptitude followed by apt-get install aptitude, or if that still fails try apt-get purge aptitude followed by apt-get install aptitude.

Before doing either of the above, I recommend a full file-system and bad-block check in case there is a problem there that caused the problem (depending on the problem, if there is one, further activity could make things worse). Also, make sure you review what will be removed in the remove/purge step before letting it proceed (it should pause to ask for permission if anything extra is changed as a result of removing that one package), to double check my thought that this is safe.


If you want a reinstall with complete config wipe: sudo apt remove --purge package sudo apt install package

That's like you never had installed the package before. I am doing this often with motion and such things.