How To Set Up Automatic Updates in Ubuntu

Latest Ubuntu versions have automatic updates enabled by default. If they are not enabled in your case, here is how to set up automatic updates in Ubuntu. You can use these steps to turn on automatic updates and enable unattended automatic updates.


How To Set Up Automatic Updates in Ubuntu

Here are the steps to turn on automatic updates in Ubuntu.


1. Update Ubuntu

Open terminal and run the following commands to update Ubuntu system.

$ sudo apt update && sudo apt upgrade

Also read : How to Set Up Static IP in Ubuntu


2. Install Unattended updates

Run the following command to install packages for unattended automatic updates

$ sudo apt install unattended-upgrades apt-listchanges bsd-mailx

Also read : How to Enable Key Based Authentication in SSH


3. Turn on Unattended Security Updates

Enable automatic updates with the following command

$ sudo dpkg-reconfigure -plow unattended-upgrades

You will see a confirmation dialog box. Enter yes to proceed.

Also read : How to Run Cron Job Every 5, 10, 15 minutes


4. Configure automatic updates

Open configuration file for automatic updates in a text editor.

$ sudo vi /etc/apt/apt.conf.d/50unattended-upgrades

Add the following line to set up email Id for alerts. Update admin@website.com below with your admin email address.

Unattended-Upgrade::Mail "admin@website.com";

Save and close the file.

Next edit the /etc/apt/listchanges.conf and set email ID

$ sudo vi /etc/apt/listchanges.conf

Add the following line. Update admin@website.com below with your admin email address.

email_address=admin@website.com

Also read : How to Use Rsync Command in Linux

Finally, open apt configuration file /etc/apt/apt.conf.d/20auto-upgrades

$ sudo vi /etc/apt/apt.conf.d/20auto-upgrades

Make sure the following two lines are present in it.

APT::Periodic::Update-Package-Lists "1"; APT::Periodic::Unattended-Upgrade "1";

The above lines will automatically check and install available updates every day.

Also add the following line to clean up downloaded archive every 7 days.

APT::Periodic::AutocleanInterval "7";

Save and close the file.

Also read : How to Disable Automatic Updates in Ubuntu


5. Test Automatic Updates

Run the following command to test if auto upgrades work, using a dry run.

$ sudo unattended-upgrades --dry-run --debug

You will see an output as below.

... 
pkgs that look like they should be upgraded: 
Fetched 0 B in 0s (0 B/s) 
fetch.run() result: 0 
blacklist: [] 
whitelist: [] 
No packages found that can be upgraded unattended and no pending auto-removals

Automatic updates are logged in /var/log/unattended-upgrades/unattended-upgrades.log file.

Leave a Reply

Your email address will not be published. Required fields are marked *