25

Say I recently installed unattended-upgrades via:

sudo apt-get install unattended-upgrades -y
sudo dpkg-reconfigure --priority=low unattended-upgrades -y

Does unattended-upgrades also include apt-get autoremove?

Or should I add a weekly cronjob atop the unattended-upgrades layer to make sure dependencies of deleted packages are removed as well, via crontab -e and then:

0 0 * * 0 apt-get autoremove -y

Note: Feel free to mention similar apt concepts besides autoremove if these are needed.

guntbert
  • 12,914
  • 37
  • 45
  • 86

2 Answers2

32

Whether or not unattended-upgrades will perform the cleanup (auto remove) is controlled by the Unattended-Upgrade::Remove-Unused-Dependencies setting in /etc/apt/apt.conf.d/50unattended-upgrades. Set it as follows to enable the cleanup -- and you should be able to remove the explicit autoremove cron-job:

Unattended-Upgrade::Remove-Unused-Dependencies  "true";
Kulfy
  • 17,416
  • 26
  • 64
  • 103
Mikhail T.
  • 521
  • 6
  • 14
  • 2
    Before enabling this, consider whether or not it's necessary - newer versions of `unattended-upgrades` have the option `Remove-New-Unused-Dependencies` enabled automatically, which basically performs `autoremove`, but only for packages newly made unused after an upgrade run. (The `Remove-Unused-Kernel-Packages` option mentioned below also appears to be enabled by default now.) – Dustin Martin Oct 11 '21 at 21:16
11

In addition to Mikhail's suggestion, it is also useful to autoremove unused kernel packages. This will keep the /boot/ partition from filling up on some Ubuntu systems. A full /boot partition can lead to issues.

Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Gryu
  • 7,279
  • 9
  • 31
  • 52
Jake Stookey
  • 111
  • 1
  • 3