Website Vidya
Linux & ServersStep-by-Step Guide

How to Set up Automatic Updates on Ubuntu 24.04

Learn how to set up automatic updates on Ubuntu 24.04 LTS using unattended-upgrades. Configure security patches, email alerts, and reboot rules.

RR
Rajesh RayLead Systems Educator
Published:
6 min read
PDF Cheat Sheet
How to Set up Automatic Updates on Ubuntu 24.04
AI Executive SummaryWebsiteVidya AI

6 min read

Learn how to set up automatic updates on Ubuntu 24.04 LTS using unattended-upgrades. Configure security patches, email alerts, and reboot rules.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Installing Unattended Upgrades and Notifier Packages
  • Step 2: Enabling the Automated Background Service
Grounded in full engineering runbookWebsiteVidya AI Engine

Maintaining a proactive security posture across your Linux servers requires applying operating system patches promptly. Unpatched vulnerabilities in core system libraries, networking daemons, or the Linux kernel represent one of the primary attack vectors targeted by automated exploit kits and threat actors. However, manually logging into every production node to execute routine package upgrades is inefficient and prone to human oversight.

To address this operational challenge, Ubuntu provides unattended-upgrades, an enterprise-grade utility that automatically downloads and installs security updates in the background. Learning how to set up automatic updates on ubuntu 24.04 enables system administrators to protect their infrastructure against zero-day exploits while maintaining total control over update frequency, package blacklists, reboot windows, and alert notifications.

In this guide, we explore the complete setup of unattended upgrades on Ubuntu 24.04 LTS (Noble Numbat). We cover package installation, configuring update origins, excluding sensitive databases and web services from auto-upgrades, scheduling automated reboot windows for kernel patches, integrating email alerts, and verifying your configuration using non-destructive dry-run tests.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat). The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • An active physical or virtual server running Ubuntu 24.04 LTS.
  • Root access or a standard user account with sudo administrative privileges.
  • An active network connection able to connect to official Ubuntu APT repositories.
  • An optional local or remote Mail Transfer Agent (such as Postfix or mailx) for alert notifications.

Step 1: Installing Unattended Upgrades and Notifier Packages

The first step is installing the unattended upgrades daemon and the system notification helpers. On minimal cloud images or custom server builds, these packages may not be pre-installed.

Update your local package index and install unattended-upgrades alongside update-notifier-common using APT.

Advertisement

The update-notifier-common package provides detection scripts that monitor system state and trigger the /var/run/reboot-required flag file when a new kernel or glibc release is installed.

# Update package index
sudo apt update

# Install unattended-upgrades and notification packages
sudo apt install -y unattended-upgrades update-notifier-common

Step 2: Enabling the Automated Background Service

Once installed, you must enable the automatic update scheduler. Ubuntu provides an interactive debconf reconfiguration utility to activate the automated daily tasks.

Run the dpkg-reconfigure command below. When prompted with the ncurses dialog asking: 'Automatically download and install stable updates?', select Yes and press Enter.

This action generates the base configuration file at /etc/apt/apt.conf.d/20auto-upgrades, enabling the daily systemd timers.

Advertisement
# Launch debconf configuration for unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades

Step 3: Configuring Update Frequencies in 20auto-upgrades

The activation step creates or updates /etc/apt/apt.conf.d/20auto-upgrades. This configuration file dictates how often APT refreshes its package catalogs, downloads packages, executes upgrades, and purges obsolete cached archives.

Open /etc/apt/apt.conf.d/20auto-upgrades in your text editor and verify that the periodic directives are configured as shown below.

Setting AutocleanInterval "7" ensures that cached deb files in /var/cache/apt/archives are purged every 7 days, preventing server disk space exhaustion.

# Edit periodic upgrade configuration
sudo nano /etc/apt/apt.conf.d/20auto-upgrades

# Recommended production settings:
# APT::Periodic::Update-Package-Lists "1";
# APT::Periodic::Download-Upgradeable-Packages "1";
# APT::Periodic::AutocleanInterval "7";
# APT::Periodic::Unattended-Upgrade "1";

Step 4: Defining Allowed Update Origins in 50unattended-upgrades

The primary configuration file for unattended upgrades is located at /etc/apt/apt.conf.d/50unattended-upgrades. This file defines which repositories are permitted to install updates automatically.

For production servers running Ubuntu 24.04 LTS, it is industry best practice to allow only security updates, while deferring general feature updates, backports, and proposed packages to controlled maintenance windows.

Open /etc/apt/apt.conf.d/50unattended-upgrades and verify the Unattended-Upgrade::Allowed-Origins section. Keep the security channel enabled while ensuring non-security repositories remain commented out.

# Edit main unattended-upgrades configuration
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

# Verify Allowed-Origins stanza contains:
# Unattended-Upgrade::Allowed-Origins {
#     "\${distro_id}:\${distro_codename}-security";
#     // "\${distro_id}:\${distro_codename}-updates";
# };

Step 5: Blacklisting Critical Services and Databases

In mission-critical server environments, certain applications—such as relational databases, web servers, or container engines—should never be upgraded automatically without administrative supervision. The unattended upgrades engine provides a flexible package blacklist.

Locate the Unattended-Upgrade::Package-Blacklist stanza inside /etc/apt/apt.conf.d/50unattended-upgrades. Uncomment the block and add packages you want to protect from automated updates.

Any package listed in this block will be ignored by unattended upgrades, ensuring that your production databases and web servers remain undisturbed until you perform manual upgrades.

# Add mission-critical packages to the blacklist in /etc/apt/apt.conf.d/50unattended-upgrades:
# Unattended-Upgrade::Package-Blacklist {
#     "nginx";
#     "apache2";
#     "mysql-server";
#     "postgresql.*";
#     "docker-ce";
#     "containerd.io";
# };

Step 6: Configuring Automated Reboots and Maintenance Windows

When security updates patch vulnerabilities in the Linux kernel or core shared C libraries (like glibc), the system must be rebooted to load the patched components into memory. While unattended upgrades can initiate reboots automatically, uncoordinated reboots during peak business hours can disrupt service availability.

To enable safe automated reboots during off-peak maintenance hours, configure the following directives inside /etc/apt/apt.conf.d/50unattended-upgrades.

Setting Automatic-Reboot-Time "03:30" instructs Ubuntu to reboot at 3:30 AM local time only if /var/run/reboot-required is present on the filesystem.

# Enable scheduled maintenance reboots in /etc/apt/apt.conf.d/50unattended-upgrades:
# Unattended-Upgrade::Automatic-Reboot "true";
# Unattended-Upgrade::Automatic-Reboot-Time "03:30";
# Unattended-Upgrade::Automatic-Reboot-WithUsers "true";

Step 7: Configuring Email Alerts and Log Auditing

To keep your operations team informed of all patch actions and potential package install errors, configure email reporting. Locate the Unattended-Upgrade::Mail directive inside /etc/apt/apt.conf.d/50unattended-upgrades.

Setting MailReport "on-change" ensures you only receive email notifications when updates are actually installed or when errors occur, avoiding daily spam for empty update runs.

Unattended upgrades records comprehensive logs for every transaction. You can audit system updates by reviewing the primary log files located in /var/log/unattended-upgrades/.

# Configure email recipient in /etc/apt/apt.conf.d/50unattended-upgrades:
# Unattended-Upgrade::Mail "[email protected]";
# Unattended-Upgrade::MailReport "on-change";

# Audit recent unattended upgrades log entries
sudo tail -n 50 /var/log/unattended-upgrades/unattended-upgrades.log
sudo tail -n 50 /var/log/unattended-upgrades/unattended-upgrades-dpkg.log

Step 8: Testing Configuration with a Dry-Run Simulation

Before relying on automatic updates in production, verify your configuration by performing a non-destructive dry run. The dry-run command simulates a live upgrade session, querying repositories and resolving dependencies without making permanent disk changes.

Execute the dry-run command with the --debug flag to view step-by-step diagnostic output from the upgrade engine.

Also verify that the background systemd timers governing periodic upgrades are active and scheduled properly.

# Perform non-destructive dry run simulation
sudo unattended-upgrades --dry-run --debug

# Verify active systemd timers
systemctl status apt-daily.timer apt-daily-upgrade.timer

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

APT lock error: Could not get lock /var/lib/dpkg/lock-frontend

Resolution: This occurs if another process (such as apt-daily.service or a background apt check) is currently running. Check which process holds the lock using sudo lsof /var/lib/dpkg/lock-frontend and wait for it to complete rather than killing it forcefully.

System fails to reboot automatically despite reboot flag

Resolution: Check whether /var/run/reboot-required exists. If active SSH sessions are preventing reboots, ensure Unattended-Upgrade::Automatic-Reboot-WithUsers "true"; is set in /etc/apt/apt.conf.d/50unattended-upgrades.

Disk full error in /var/cache/apt/archives

Resolution: Enable automatic archive cleanup by setting APT::Periodic::AutocleanInterval "7"; in /etc/apt/apt.conf.d/20auto-upgrades, and run sudo apt clean to free up space immediately.

Security Best Practices and Hardening

Restrict Allowed-Origins in /etc/apt/apt.conf.d/50unattended-upgrades to security channels only. Avoid enabling backports or proposed updates on mission-critical servers.

Always blacklist critical database and clustering services (such as PostgreSQL, MySQL, and Elasticsearch) to prevent automated restarts from breaking quorum or dropping active transactions.

Ensure an authenticated SMTP relay or local MTA is configured when enabling email alerts, protecting notification delivery from being dropped or spoofed.

Regularly inspect /var/log/unattended-upgrades/unattended-upgrades.log to audit applied security CVE patches and identify blocked dependencies.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

3 FAQs
Yes, Ubuntu Server 24.04 installs the unattended-upgrades package by default during server installation. However, configuring reboot windows, package blacklists, and email notifications requires manual customization.
Inspect the filesystem for the flag file /var/run/reboot-required. If this file exists, a newly installed kernel or core system library requires a reboot. You can view which packages triggered the reboot by reading /var/run/reboot-required.pkgs.
Yes, you can force an immediate upgrade run by executing sudo unattended-upgrades -v. Add the --debug flag if you wish to see detailed step-by-step diagnostic output.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout