34

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?

1 Answer 1

47

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
4
  • 12
    That's it! Thank you. I modified the grep argument from 'Depends' to '[ |]Depends: [^<]' to exclude PreDepends and alternative package (Depends: <package>) entries. The apt-get arguments would need to be --reinstall install to do the actual reinstalling I was after.
    – Forage
    Mar 30, 2013 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, 2015 at 9: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. Aug 24, 2020 at 7:52
  • @user1202136 To see what packages are to be reinstalled, execute the command after replacing the part xargs .......... by just cat Nov 1, 2020 at 20:33

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.