As far as I know I can uninstall a program from Ubuntu using this command...

$ sudo dpkg -r packagename

But this does not remove the dependencies while the packagename installed. To remove all files including dependencies we need to apply this command...

$ sudo apt-get --purge autoremove packagename

But my question is removing the package and all its dependencies is really a good practice? Will --purge autoremove command make my system as it before installing the packagename package? Or occasionally I might end up with some broken files and my system might crash while trying to remove everything? Actually I am afraid to implement the --purge autoremove command and want to know expert opinion before practising this!

  • 1
    autoremove doesn't require a package name after it. – saiarcot895 May 10 '15 at 19:46
  • @saiarcot895 if so then how terminal will know which package to remove? – Roy Emmarson May 10 '15 at 19:57
  • 2
    It will remove all packages that, according to its database, were automatically installed for a package that is no longer installed. (In other words, if a package is marked as being automatically installed, but no other package depends on that package, then it's marked for removal.) – saiarcot895 May 10 '15 at 21:58
  • 1
    On a related note, check out deborphan, it will search out (and list, only) unnecessary packages more thoroughly than apt-get autoremove. Though if you have non-Ubuntu software (like, built from sources) where you manually installed dependecies, be careful with deborphan results, it may list something you want to keep. – hyde May 11 '15 at 5:15
  • 2
    @MikeFriedman: I recommend that you use apt-get whenever possible rather than using both apt-get and dpkg (the exception being if you're installing a deb file, in which case you'll need to use dpkg). To remove a package using apt-get, it's just sudo apt-get remove packagename. I just did a test, and you can indeed use sudo apt-get --purge autoremove packagename to remove the package and any unused packages you have (after removing the package). – saiarcot895 May 11 '15 at 12:11

It should be quite safe. Autoremove removes only packages, which were installed by dependency of a removed package. They should not be needed. You are correct. Your system should be as before you installed 'packagename'.


Autoremove only removes orphaned packages. Meaning that it is completely safe to use without disrupting any functional or currently installed programs.

  • I wouldn't say "completely safe", more like 99,5% safe: Non-Ubuntu programs may depend on libraries, which are installed as dependencies of some Ubuntu programs. So if you autoremove the Ubuntu program, it removes the lib, and non-Ubuntu program also stops working. Of course this is rather trivial to fix by figuring out which library got removed, and explicitly installing it with apt-get install (then autoremove will not remove it). – hyde May 11 '15 at 13:22

It is quite safe most of the times, but when you use it you must check your terminal for the names of the packages that are about to be removed because sometimes errors happen. Do not agree to the removal of dependencies without having double checked the names of the packages that are about to be removed and see if there is any that shouldn't normally be there. Check what happened to me a few days before.

  • Although I agree with the advice to take a look at the packages that will be removed before pressing y when running sudo apt-get autoremove, what happened to you doesn't seem to be an example of this. This question is about removing packages that were installed as dependencies but are no longer needed. In your case, it was about removing a package that still was a dependency of another installed package. (In your case, if there was an inadvertently removed package it was the reverse dependency.) – Eliah Kagan May 10 '15 at 20:17
  • @EliahKagan Yes I agree. I wrote that answer in order to point out that you should always check as there is the possibility of errors. I mention my experience only to depict that errors do happen with the apt-get not to link it with what the OP asks. It is just a side note. :P – Adam May 10 '15 at 23:12

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.