35

I've got a package installed that is broken (the package itself, not its dependencies). Reinstalling it with sudo dpkg-reconfigure <package> or sudo apt-get --reinstall install <package> did not do the trick. I'd like to try and reinstall the package, including all its currently installed dependencies. Is there a way to do this?

Forage
  • 1,530

1 Answers1

50

You can check all package dependencies with apt-cache:

apt-cache depends <package>

Using the results of that command, we get the following one, which re-installs <package> and its dependencies:

apt-cache depends <package> | grep '[ |]Depends: [^<]' | cut -d: -f2 | tr -d ' ' | xargs sudo apt-get --reinstall install -y
  • 12
    That's it! Thank you. I modified the grep argument from 'Depends' to '[ |]Depends: [^<]' to exclude PreDepends and alternative package (Depends: ) entries. The apt-get arguments would need to be --reinstall install to do the actual reinstalling I was after. – Forage Mar 30 '13 at 15:05
  • 4
    For that you have not tested it, it's pretty brave to post it without further explanation. After all you delete a few packages. – A.B. Mar 25 '15 at 09:14
  • 1
    Nice! I suggest removing the -y. It's kind of nice to get a chance to confirm what packages are to be reinstalled. – user1202136 Aug 24 '20 at 07:52
  • @user1202136 To see what packages are to be reinstalled, execute the command after replacing the part xargs .......... by just cat – Maarten Fokkinga Nov 01 '20 at 20:33