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?

  • 1
    yum has history undo. Commented Jan 15, 2018 at 9:18
  • @WeijunZhou Thank you. I also discovered that dnf also has the ability to autoremove a specific package. I am considering switching to Fedora (I'm on Debian), but I'll try to get yum working on Debian first.
    – Rolf
    Commented Jan 15, 2018 at 9:34
  • dnf is just a successor of yum. Commented Jan 15, 2018 at 9:38

3 Answers 3


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 the mypackage 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 effectively autoremoves by default. This won’t help you right now though since it will want to remove the same 166MiB of packages as apt autoremove.

As pointed out by Weijun Zhou, yum and dnf do manage package changes as units which can be undone (in some circumstances). dnf history will list the transactions stored in the history, and dnf history rollback or dnf history undo can be used to roll the history back or undo a specific transaction (if possible). I’m not sure yum or dnf 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.

  • Thank you. I think that apt should have the ability to "autoremove" a specific package. In this particular case, it would have the same effect, and would also be an acceptable solution. Indeed yum and dnf deal with RPM packages. Debian is packaged in 'deb' packages. Trying to replace APT with yum or dnf on a Debian system seems impractical.
    – Rolf
    Commented Jan 15, 2018 at 9:55
  • A package-specific autoremove couldn’t always be relied upon to undo a package installation, because the package installation might have pulled in a package which is of interest to some other installed package. See this question for an example where this wouldn’t work. Commented Jan 15, 2018 at 10:03
  • I understand what you're saying. However I'm sure it's possible, with edge cases, of course. What I'm seeing is apt-get installing suggested and recommended package, then not removing them, which is default behavior. I want to modify this behavior (in the uninstall stage) but only for a specific package.
    – Rolf
    Commented Jan 15, 2018 at 11:04
  • 1
    I understand what you’re after, I’m just saying it can’t be done currently. If apt-get remove --autoremove mypackage only removed autoremovable packages which were in mypackage’s dependency tree, it would give the results you’re after (or close enough), but it currently doesn’t do that. There is one way of getting what you’re after currently, but it relies on a process change rather than a tool change: never leave autoremovable packages lying around — either always remove them, or mark them as manually installed if you want to keep them. Commented Jan 15, 2018 at 12:25

By the way:

I found that the most reliable way to "undo" an install operation is to look at the apt log and uninstall all packages which were installed by this operation.

Therefore I created a solution to my problem. It helps with parsing the apt log and reverting operations.

This is how I would use it:

List latest apt operations:

96 /usr/bin/unattended-upgrade
97 apt-get install adb
98 apt-get dist-upgrade
99 /usr/bin/unattended-upgrade
100 apt-get install qemu-system

Display details about all packages which were installed by operation #100 (the last one)

sudo apt-history 100 Install
seabios:amd64 (1.10.2-1, automatic), ipxe-qemu:amd64 (1.0.0+git-20161027.b991c67-1, automatic), qemu-system-mips:amd64 (1:2.8+dfsg-6+deb9u3, automatic), openbios-sparc:amd64 (1.1.git20161120-2, automatic), qemu-system-misc:amd64 (1:2.8+dfsg-6+deb9u3, automatic), qemu-system-ppc:amd64 (1:2.8+dfsg-6+deb9u3, automatic), libvdeplug2:amd64 (2.3.2+r586-2.1, automatic), qemu-system-x86:amd64 (1:2.8+dfsg-6+deb9u3, automatic), openhackware:amd64 (0.4.1+git-20140423.c559da7c-4, automatic), libspice-server1:amd64 (0.12.8-2.1+deb9u1, automatic), libxenstore3.0:amd64 (4.8.3+xsa262+shim4.10.0+comet3-1+deb9u6, automatic), qemu-utils:amd64 (1:2.8+dfsg-6+deb9u3, automatic), qemu-efi:amd64 (0~20161202.7bbe0b3e-1, automatic), qemu-system-sparc:amd64 (1:2.8+dfsg-6+deb9u3, automatic), libxen-4.8:amd64 (4.8.3+xsa262+shim4.10.0+comet3-1+deb9u6, automatic), libfdt1:amd64 (1.4.2-1, automatic), qemu-slof:amd64 (20161019+dfsg-1, automatic), qemu-system-arm:amd64 (1:2.8+dfsg-6+deb9u3, automatic), qemu-system-common:amd64 (1:2.8+dfsg-6+deb9u3, automatic), openbios-ppc:amd64 (1.1.git20161120-2, automatic), qemu-system:amd64 (1:2.8+dfsg-6+deb9u3)

Uninstall these packages and their configuration.

sudo apt-get remove --purge `apt-history 100 Install --as-apt-arguments`

Warning: to be safe, only do this for the last install command and roll back one command at a time.


Inspired by Stephen's answer I used

cat /var/log/apt/history.log | grep -Po "Install: \K.*$UNINSTALL_THIS.*" | sed -E 's/:[^\)]*\),*//g'

to print a copy-pastable list of the packages to remove for cockpit to use sudo apt remove <paste>

For explanation of the grep command see: What does grep -Po '...\K...' do? How else can that effect be achieved?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .