10

I was trying to get musepack encoder support built into ffmpeg today, and I inadvertently broke a few things but I'm not sure exactly which package I installed which broke them. How can I remove ALL packages I installed today, and start again from scratch more carefully?

I can see a list of them in "Ubuntu Software Center" under today's date in the "History", but I don't want to go through uninstalling them one-by-one, because there are hundreds to do.

3 Answers 3

16
grep -e `date +%Y-%m-%d` /var/log/dpkg.log | awk '/install / {print $4}' | uniq | xargs apt-get -y remove

found on commandlinefu worked fine for me

4
  • This will remove only packages installed by dpkg, not by apt.
    – Pilot6
    May 30, 2015 at 11:33
  • I just tested the grep -e `date +%Y-%m-%d` /var/log/dpkg.log | awk '/install / {print $4}' | uniq output, was exactly the packages I installed using apt-get today!! nice script buddy, +1.
    – dariush
    Jan 8, 2016 at 17:48
  • You may need add one another parameter to apt-get: apt-get -y --allow-remove-essential remove Sep 3, 2016 at 12:47
  • E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root? even with sudo
    – arilwan
    Nov 22, 2021 at 11:30
6

The file /var/log/apt/history.log has what you need. Take a look at the answer: How to reinstall many removed packages at once? it's a more detailed answer.

1

Disclaimer: Nala is still in a development stage, and is not recommended for any professional use.

For apt packages

If you're ready to use the command line to install new packages, it's possible to get an easy undo feature with the more modern apt front-end called nala (for 22.04 you have to enable the "universe" repository). Note: This will only work for apt/.deb packages.

sudo apt install nala

From this point, use nala to install new packages on your system, using:

sudo nala install <package-name>

Leave security updates etc. to the unattended-upgrades package.

Now, when you run the command nala history, you get a list of the commands run with nala, including installed packages. To filter only new installations, use:

nala history | grep install

An added bonus of the history feature is that you can undo any step in the history, so that you can easily reverse package installation procedures. This can be done by issuing the command:

sudo nala history undo <ID>

Where <ID> is the ID number of the transaction in the history list you want to undo.

For snap packages

Snap has its own "undo" feature, where you can easily revert to the previously installed version. This is done with:

sudo snap revert <package-name>

In case you want to revert to a specific revision of a snap package, this can be stated as well;

sudo snap revert <package-name> --revision <rev ID>

For snaps, also see here.

You must log in to answer this question.

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