Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Set Up Automatic Updates on Ubuntu

Use unattended-upgrades, the Software & Updates app or a startup script to keep Ubuntu patched.

VPS and Cloud Servers3 min read22 screenshots

Automatic updates save time and keep your system safe, which matters most on servers.

Method 1: Terminal (unattended-upgrades)

Step 1: Install the tool

sudo apt install unattended-upgrades
Installing unattended-upgrades

It is often installed by default.

Step 2: Check the configuration file

The settings are in /etc/apt/apt.conf.d/50unattended-upgrades. Open it:

sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

In the Allowed-Origins section these lines (without a // in front) enable security updates:

"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
"${distro_id}ESMApps:${distro_codename}-apps-security";
"${distro_id}ESM:${distro_codename}-infra-security";
  • The first line allows updates of the current release.
  • The second allows security updates.
  • The last two are for Extended Security Maintenance (ESM), which gives security patches after the normal support ends.
    The unattended-upgrades configuration file

Step 3: Set how often

Edit /etc/apt/apt.conf.d/20auto-upgrades:

sudo nano /etc/apt/apt.conf.d/20auto-upgrades
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

The first line refreshes the package list every day, and the second installs the allowed updates every day. The number is the number of days.

You can create this file with sudo dpkg-reconfigure --priority=low unattended-upgrades.

The automatic update settings

Step 4: Restart the service

sudo systemctl restart unattended-upgrades
Restarting the service
sudo systemctl status unattended-upgrades
Checking the service status

The status should be active.

Step 5: Test

sudo unattended-upgrades --dry-run --debug
Running unattended-upgrades in debug mode

--dry-run shows what would happen without installing anything.

Method 2: Software & Updates (graphical)

Open Software & Updates and go to the Updates tab. Set Automatically check for updates to Daily, and under When there are security updates choose Download and install automatically.

The Software & Updates window

Method 3: A startup script

Step 1: Create the script

touch ~/autoupd.sh && chmod +x ~/autoupd.sh
Creating the shell script

Step 2: Add the commands

#!/bin/bash
sudo apt update && sudo apt -y upgrade
sudo snap refresh
flatpak update -y
The update script

The script needs sudo without a password prompt, so this method suits desktops where you set that up. For servers use Method 1.

Step 3: Run it at login

Open Startup Applications from the application menu.

Opening Startup Applications

Click Add.

Adding a startup program

Enter a name, browse to the script and click Add.

Choosing the script
The startup program added

Advanced settings

Edit /etc/apt/apt.conf.d/50unattended-upgrades.

Email reports

Unattended-Upgrade::Mail "you@example.com";
Setting the email address

Choose when to send mail:

Unattended-Upgrade::MailReport "on-change";

The values are always, only-on-error and on-change.

Setting the mail report value

A mail program such as mailutils must be installed. Restart the service after changes:

sudo systemctl restart unattended-upgrades
Restarting the service

Reboot after upgrades

Some updates (like a new kernel) need a reboot. The file /var/run/reboot-required tells you. To reboot automatically:

Unattended-Upgrade::Automatic-Reboot "true";
Enabling automatic reboot

Set it to false to never reboot by itself.

Reboot even when users are logged in:

Unattended-Upgrade::Automatic-Reboot-WithUsers "true";
Rebooting with users logged in

Reboot at a set time:

Unattended-Upgrade::Automatic-Reboot-Time "02:00";
Setting the reboot time

Clean up

Remove dependencies that were installed with an upgrade and are no longer needed:

Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
Removing new unused dependencies

Remove unused packages in general:

Unattended-Upgrade::Remove-Unused-Dependencies "true";
Removing unused packages

Remove old kernels:

Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Removing unused kernel packages

Check the logs in /var/log/unattended-upgrades/.

Quick recap

  • Install unattended-upgrades and keep 20auto-upgrades at "1".
  • Test with --dry-run, and set the reboot time you want.