apt-get autoremove wants to remove 1000+ packages and everything
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!
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 likesudo 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.