keepcalculator

06 Numbers and Powers

Enable Automatic Updates Debian: Step-by-Step

Card No. 06·87747 · Updated · Standard formula, shown below

To enable automatic updates on Debian, you install the unattended-upgrades package and enable the corresponding systemd timer. This configures the system to download and install security and other selected updates automatically, typically on a daily schedule, without manual intervention.

Why Use Automatic Updates on Debian

Debian’s default installation does not enable automatic updates. The maintainers intentionally leave this decision to the administrator, because an unattended system that installs a broken update can become unavailable or unstable. However, for most servers and desktops, the benefits of automatic security updates outweigh the risks. Critical vulnerabilities are often exploited within days of disclosure, and a system that updates itself promptly is far less likely to be compromised. Automatic updates also reduce the administrative burden of manually checking for and installing patches on multiple machines.

Debian’s unattended-upgrades tool is the standard, supported way to achieve this. It is designed to be conservative: by default it only installs updates from the Debian security repository and the updates repository (for stable releases). It does not perform distribution upgrades (e.g., from Debian 11 to 12) and it will not install packages that require configuration prompts unless you explicitly allow them. This makes it a safe choice for production systems.

Prerequisites and What You Need

Before you begin, ensure you have:

  • Root or sudo access to the Debian system.
  • A working internet connection to the Debian repositories.
  • An active Debian release (stable, oldstable, or testing) – the commands work on all of them, but repository names differ slightly.
  • Basic familiarity with the terminal and editing files with a text editor like nano or vim.

Step-by-Step: Install and Enable

The entire setup takes about five minutes. Here are the exact steps:

  1. Update the package lists: sudo apt update
  2. Install the required packages: sudo apt install unattended-upgrades apt-listchanges (apt-listchanges is optional but shows you what will change before installation).
  3. Run the interactive configuration script: sudo dpkg-reconfigure -plow unattended-upgrades. You will be asked if you want to automatically download and install stable updates; choose Yes. This creates the file /etc/apt/apt.conf.d/20auto-upgrades with the following two lines:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

If you prefer not to use the interactive script, you can create that file manually with the same content.

Configuring What Updates Are Installed

The main configuration file is /etc/apt/apt.conf.d/50unattended-upgrades. Open it with sudo nano /etc/apt/apt.conf.d/50unattended-upgrades. The file contains many commented-out options. The most important section is the origins list, which defines which repositories are considered for automatic updates. By default, it includes:

  • origin=Debian,codename=${distro_codename},label=Debian-Security – security updates for the stable release.
  • origin=Debian,codename=${distro_codename}-updates,label=Debian – regular updates (e.g., point releases).

You can uncomment other lines to include backports or third-party repositories, but doing so increases the risk of installing packages that were not thoroughly tested for your release. For most users, the defaults are sufficient.

Other useful settings in the same file:

  • Unattended-Upgrade::Automatic-Reboot "false"; – set to true if you want the system to reboot automatically after installing updates that require it. You can also set Automatic-Reboot-Time to a specific hour.
  • Unattended-Upgrade::Remove-Unused-Kernel-Packages "true"; – removes old kernel packages after a successful upgrade, preventing the boot partition from filling up.
  • Unattended-Upgrade::Remove-Unused-Dependencies "true"; – cleans up packages that are no longer needed.

Enabling the Timer and Checking Status

The unattended-upgrades package installs a systemd timer called apt-daily-upgrade.timer. On most systems it is enabled by default, but you can verify and start it with:

sudo systemctl enable apt-daily-upgrade.timer
sudo systemctl start apt-daily-upgrade.timer

To see when the timer will next run, use systemctl status apt-daily-upgrade.timer or systemctl list-timers | grep apt. The timer triggers a service that runs unattended-upgrades daily, typically at a random time between 6:00 and 7:00 AM to avoid load spikes on mirrors.

You can also run the upgrade manually to test your configuration: sudo unattended-upgrades --dry-run (shows what would be done) or sudo unattended-upgrades (actually runs it).

Common Problems and How to Fix Them

Even with a correct setup, you might encounter issues:

  • Updates are not installed. Check the log file /var/log/unattended-upgrades/unattended-upgrades.log. The most common cause is a misconfigured origin list – for example, if you are on Debian testing, the default origins do not match, so you must add the appropriate lines for testing or sid.
  • The system reboots unexpectedly. If you set Automatic-Reboot to true, the system will reboot after installing updates that require it. To prevent this, set it to false or specify a time window with Automatic-Reboot-Time.
  • Packages are held back. If a package has been held (with apt-mark hold) or has a configuration change, it will be skipped. Check dpkg --audit and the log for details.
  • No space left on device. Old kernels and packages can accumulate. Enable the removal options mentioned above, or run sudo apt autoremove manually.

Security and Safety Considerations

Automatic updates are generally safe, but you should be aware of the trade-offs. The most significant risk is that an update could break a service you depend on. To mitigate this:

  • Always keep a recent backup or snapshot of your system, especially before enabling automatic updates for the first time.
  • Monitor the logs regularly – you can set up email notifications by uncommenting the Unattended-Upgrade::Mail option in the configuration file and providing an email address.
  • Consider enabling automatic reboots only if you are certain no critical services will be interrupted, or use a maintenance window.
  • For production servers, test updates on a staging system first if possible.

It is also worth noting that unattended-upgrades will not install packages from third-party repositories unless you explicitly add their origins. This is a deliberate safety measure to avoid unexpected changes.

Alternatives to unattended-upgrades

While unattended-upgrades is the standard tool, there are other approaches:

  • cron-apt: A simpler tool that runs apt commands on a schedule. It is less configurable but lighter. It can be set to only download updates or to install them, and it can send email reports.
  • Ansible or other configuration management: If you manage many Debian machines, you can use Ansible to run apt upgrade on a schedule, with more control over when and how.
  • Debian’s own apt periodic options: You can set APT::Periodic::Update-Package-Lists and APT::Periodic::Unattended-Upgrade in a file under /etc/apt/apt.conf.d/ without installing the full unattended-upgrades package, but you lose the fine-grained control over origins and reboots.

Frequently Asked Questions

Will automatic updates break my system?

It is possible, but unlikely. Debian’s stable repository is heavily tested, and security updates are minimal by design. The biggest risk is a package that conflicts with a locally installed program. You can reduce the risk by only enabling security updates and by monitoring the logs.

How do I see what was updated?

The log file /var/log/unattended-upgrades/unattended-upgrades.log records every action. You can also check /var/log/dpkg.log for package installation history. If you enable the mail option, you will receive a summary after each run.

Can I exclude specific packages from automatic updates?

Yes. In the 50unattended-upgrades file, uncomment the line Unattended-Upgrade::Package-Blacklist and add the package names you want to keep untouched, for example "vim";.

Does this work on Debian testing or unstable?

It works, but the default origins list does not include testing or unstable. You must edit the origins list to add lines like origin=Debian,codename=${distro_codename},label=Debian for testing. Be aware that testing and unstable receive more frequent and less tested updates, so automatic installation is riskier.

How do I disable automatic updates if I change my mind?

Remove the file /etc/apt/apt.conf.d/20auto-upgrades or set the values to "0";. You can also stop and disable the timer with sudo systemctl disable --now apt-daily-upgrade.timer. The package itself can be removed with sudo apt remove unattended-upgrades.

Will it automatically reboot my server?

Only if you set Unattended-Upgrade::Automatic-Reboot "true";. By default it is false, so updates that require a reboot will be installed but not activated until you reboot manually.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →