So I install a package
apt-get install mypackage
apt-get installs the package with dependencies, and reports that 10 megabytes were installed on my disk.
But I change my mind, so I go
apt-get remove mypackage
And apt-get announces that 166 kilobytes will be freed.
I don't want to litter my disk with leftovers, so I try
apt-get autoremove mypackage
Now apt-get wants to remove 166 megabytes from my disk.
How do I, you know, undo the last install operation, or just uninstall a single package and all its dependencies?
Alternatively, is there another package management tool that I could use (even on different distro), which would roughly treat install operations as atomic operations which can be done and undone?
Best Answer
APT doesn’t manage package changes as transactions, so there’s no built-in operation to undo a package installation (or any other package manipulation). However, it does log all the operations it performs, grouped by end-user request: if you look in
/var/log/apt/history.log
, you’ll find themypackage
installation, along with a list of all the other packages which were installed automatically alongside it. You can use this to undo the installation manually.You could also use
aptitude
instead, for your general package management: it effectivelyautoremove
s by default. This won’t help you right now though since it will want to remove the same 166MiB of packages asapt autoremove
.As pointed out by Weijun Zhou,
yum
anddnf
do manage package changes as units which can be undone (in some circumstances).dnf history
will list the transactions stored in the history, anddnf history rollback
ordnf history undo
can be used to roll the history back or undo a specific transaction (if possible). I’m not sureyum
ordnf
can be used properly instead of APT on Debian-based systems; you might need to switch to Fedora, RHEL or CentOS if you want to use those tools for all your package management.