242

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!
1
  • These are great two separate questions. One is how to reinstall a package, which is in the title and which is answered. The other one is, how to deal with aptitude crash on a too wide terminal. Apr 4 at 7:31

5 Answers 5

390
$ 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
7
  • 18
    what's that -A5 you are grepping ? Jan 30, 2010 at 12:51
  • 99
    man grep | grep -- "-A"
    – user1686
    Jan 30, 2010 at 13:04
  • 38
    What's that -- you're grepping?
    – Desty
    Sep 11, 2014 at 9:55
  • 19
    man getopt, look under PARSING
    – Tino
    Nov 17, 2014 at 16:43
  • 37
    -A5 shows the matched line plus the following 5 lines. -- stops parsing of options, thus interpreting anything that comes after as positional arguments, avoiding having to escape the dash in the expression -A which would otherwise be interpreted as an option to grep itself.
    – jjmontes
    Nov 18, 2014 at 18:20
153

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.

4
  • 12
    Thank you for being the only correct, complete, non-snarky answer.
    – Cerin
    Apr 5, 2013 at 4:55
  • 6
    @Cerin: I wouldn't call the other answers overly snarky: even the "read the man page" one actually gave the answer as well as how to find it. Apr 5, 2013 at 13:50
  • 56
    @DavidSpillett, I strongly disagree. The man pages are usually very poorly written and are very unfriendly to newbies. For example, the paragraph on the "--reinstall" option doesn't mention that you have to use it with the "install" argument. A newbie might rightfully ask "why do I have to tell it to install AND reinstall?" An answer telling someone to RTFM is the worst kind of answer and it pains me to see it with the most votes, especially when a complete and actually helpful answer is near the bottom.
    – Cerin
    Apr 5, 2013 at 21:34
  • 2
    You can use apt instead apt-get too: sudo apt install --reinstall packagename
    – Flimm
    Aug 31, 2021 at 14:45
34

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
2
  • 8
    And if you need to restore config files only, in some cases (if they are managed by ucf) you should use UCF_FORCE_CONFFMISS=1 apt-get --reinstall install [pkgname]. Feb 23, 2015 at 18:04
  • 2
    This answer deserves a BIG upvote.This is what you need when you want to "fully reinstall" a package. E.g. a simple --reinstall of vsftpd doesn't re-create the config file, even if the file doesn't exist anymore. A "Remove+Purge+(Re)install" does the job instead.
    – Kar.ma
    Feb 22, 2019 at 15:31
14

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.

6
  • Thanks a lot! apt-get remove followed by apt-get install did the trick! Jan 30, 2010 at 0:32
  • It's a long time ago that I did things like a full filesystem check or similar. Could you please give me a short hint howto do that? Jan 30, 2010 at 0:50
  • 1
    fsck -f <block_device> such as fsck /dev/sda1. The filesystem will need to be unmounted or mounted read-only at the time so as this is likely to be your root filesystem you should reboot into single-user-mode or boot from something else like a live cd. Jan 30, 2010 at 1:24
  • 2
    You can use tune2fs to mark the filesystem as having been mounted more times than its set limit, that should force a check next boot. Assuming the filesystem is ext2/3/4: tune2fs -C 99 <device>, or in case you have mount count based checking turned off, turn it on at the same time with something like tune2fs -c 17 -C 99 <device>. Jan 30, 2010 at 13:20
  • 2
    touch /forcefsck;reboot
    – user23307
    Jan 30, 2010 at 14:53
3

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.

3
  • The problem with that technique is that it deletes all your changes to the settings under /etc/... which may not be what you want... Sep 29, 2020 at 17:45
  • In other cases it can be exactly what you want. Sometimes you just want to get back original config or just do a cleanup
    – Niwla23
    Dec 30, 2020 at 12:30
  • 1
    Absolutely. Actually, when I test my new packages I do that a lot until I'm satisfied with the installation process. So it can be very useful. On the other hand, it can be a gotcha if you don't first backup your settings with some specific data which you don't have anywhere else (you probably can come up with it again, but it can be time consuming). Dec 30, 2020 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.