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

435

Solution 1

$ 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

Solution 2

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.

Solution 3

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

Solution 4

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.

Solution 5

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.

Share:
435

Related videos on Youtube

Shashi
Author by

Shashi

Updated on September 17, 2022

Comments

  • Shashi
    Shashi almost 2 years

    I am developing a class in X++. In this class I need to send messages to third party application using a WCF custom channel written C#.

    So my questions are: 1) Is it possible to create and use a WCF custom channel to send message inside a X++ method?

    2) In WCF, channels are created using channel factories. They are declared something like IChannelFactory<IOutputChannel> fact; Can this be done in X++ also?

    Thanks in advance

    • Admin
      Admin about 2 years
      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.
  • Yejin
    Yejin over 14 years
    Thanks a lot! apt-get remove followed by apt-get install did the trick!
  • Yejin
    Yejin over 14 years
    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?
  • David Spillett
    David Spillett over 14 years
    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.
  • Yejin
    Yejin over 14 years
    what's that -A5 you are grepping ?
  • Yejin
    Yejin over 14 years
    @David: Is there a way to force a filesystem check on next reboot ?
  • user1686
    user1686 over 14 years
    man grep | grep -- "-A"
  • David Spillett
    David Spillett over 14 years
    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>.
  • user23307
    user23307 over 14 years
    touch /forcefsck;reboot
  • Cerin
    Cerin about 11 years
    Thank you for being the only correct, complete, non-snarky answer.
  • Cerin
    Cerin about 11 years
    @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.
  • Desty
    Desty almost 10 years
    What's that -- you're grepping?
  • Tino
    Tino over 9 years
    man getopt, look under PARSING
  • jjmontes
    jjmontes over 9 years
    -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.
  • Dimitry K
    Dimitry K over 9 years
    @jjmontes So technically quotes around "-A" are not necesary: man grep | grep -- -A
  • Skippy le Grand Gourou
    Skippy le Grand Gourou over 9 years
    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].
  • Kar.ma
    Kar.ma over 5 years
    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.
  • Alexis Wilke
    Alexis Wilke over 3 years
    The problem with that technique is that it deletes all your changes to the settings under /etc/... which may not be what you want...
  • Niwla23
    Niwla23 over 3 years
    In other cases it can be exactly what you want. Sometimes you just want to get back original config or just do a cleanup
  • Alexis Wilke
    Alexis Wilke over 3 years
    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).
  • Mikko Rantalainen
    Mikko Rantalainen almost 3 years
    @DimitryK Yes, grep -- "-A" is exactly the same thing as grep -- -A. The quotes are interpreted by the shell and grep always sees the second parameter as -A. And obviously the -- is required before that to make sure it's interpreted as query instead of flag -A. (Windows programmers will have different experience because cmd has much less smarts than UNIX shell.)
  • Flimm
    Flimm almost 3 years
    You can use apt instead apt-get too: sudo apt install --reinstall packagename