Score:5

apt-get autoremove wants to remove 1000+ packages and everything

in flag

It lists 1546 packages to be removed. Including xorg, xserver and other core packages. I entered "yes" in the past and as expected it bricked the OS I had to reinstall it from scratch. This time I answered "no" and tried:

sudo apt-get -y update --fix-missing

but it still wants to remove everything. How can I fix that please!

Organic Marble avatar
us flag
What did you do to cause the situation? Probably you removed some metapackage like a desktop.
Terrance avatar
id flag
Look in `/var/log/apt/history.log` for something recently removed. A possible command that might help would be `cat /var/log/apt/history.log | grep -i remove`
guiverc avatar
cn flag
We don't know your product or release (*though description implies a desktop install, it's best if we're provided that information and don't need to guess*) , but my guess is you added a source intended for another system/release, which caused package conflicts & thus where you are now (*removing loads of packages was the fix for user-created conflict*), but without specifics we can only guess. Giving us your OS, release details, and actual packages (so we can look up some & give a specific reason & aren't just having to guess at *cause* to your described *effect*)
U.V. avatar
cn flag
This happened to me on a 3 year old system started with an ubuntu-studio 18.04 but running xfce4 and mate apps and some gnome apps. Many upgrades and tons of stuff. Suddenly thunderbird, firefox and the lot was gone. Lets say the dependency structures that apt creates are simply broken after such a long time of installing and upgrading and removing. I always wondered about the mathematical completeness of this system and now I know its incomplete. Meaning the composition of too many dependency graphs is not correctly reversible. So we gotta be careful (or reinstall more often) ;)
Score:4
cn flag

This happens most commonly when folks bolt a Desktop onto a Minimal install. But it can happen when you bolt ANY kind of major stack onto an Ubuntu system.

In the Desktop example, it means the entire desktop stack is hanging on a single metapackage (like the ubuntu-desktop package). When you remove some element or application of the Desktop --which removes the desktop metapackage-- that action makes the whole desktop stack eligible for autoremoval.

Prevention

  • When folks use the real Desktop Installer, there's an additional layer of apt-marking protection to prevent folks from autoremoving their whole desktop.

  • You can also explicitly install (or apt-mark) the applications you use. That way, most of your desktop dependencies won't be auto-removed.

    sudo apt install shotwell         # Example of explicitly installing
    sudo apt-mark manual shotwell     # Example of apt-marking
    
  • install using Task Packages, for example Ubuntu MATE is installable by

    sudo apt-get install ubuntu-mate-desktop^
    

    Note the ^, it means task; installing this way will prevent ruining the system if someone wants to run potentially dangerous commands like sudo apt autopurge ubuntu-mate-desktop for meta-package.

Recovery

  • You can simply re-install the desktop task package.

    sudo apt install --reinstall ubuntu-desktop^ # Example of re-installing a Ubuntu desktop task
    
  • You can also copy the long list of removals and paste that list into an install command. Note that naming a package makes it ineligible for future autoremovals, but your concern seems to be too many autoremovals instead of too few. If you need to recover that list, it's in your /var/log/apt/history.log file.

N0rbert avatar
zw flag
Too many errors. Using Ubuntu minimal is absolutely normal. Shame on Canonical that they [dropped](https://discourse.ubuntu.com/t/poll-about-possible-netboot-mini-iso-revival-in-future-ubuntu-releases/19457) it. Installation of desktop systems should be done using task-packages, like `sudo apt-get install ubuntu-mate-desktop^`. Normally designed meta-packages should not cause huge autoremoval. Running `sudo apt autopurge ubuntu-mate-desktop` does not ruin the system. Fix your great and useful `ubuntu-desktop` first. `apt-mark` is unreliable, use pin instead.
user535733 avatar
cn flag
@N0rbert you're right -- I missed Task Packages. Would you mind editing in an additional bullet for that?
N0rbert avatar
zw flag
Done, hope it is now better any failproof.
Score:0
in flag

If you think autoremove is removing things you want to keep, for each package you should:

  • use dpkg -l | grep $shortpackagename to check if there is a newer version also installed, in which case it is ok to remove the older one
  • use apt rdepends $packagename to see if there is a parent package that you also want. If there is, install that parent package or a reverse dependency of that parent
  • If there is no (obvious) parent dependency package you want to keep, but you still want to keep it, apt install $packagename so it doesn't get uninstalled by autoremove.

A good example of the above (as mentioned in comments), if autoremove wants to remove xorg then install ubuntu-desktop and you will probably find that many of the autoremoves will now have a parent dependency installed and the list will get shorter.

Once the list is short enough that what is left is either obsolete packages or things you are sure you don't care about, then autoremove is safe.

This situation is not normal, it doesn't happen automatically, It is caused by, at some point, something critical being removed from the system that causes some important parent package (like ubuntu-desktop) to be removed.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.