How to set up automatic updates on Ubuntu Server 18.04, 20.04 or 22.04
Last updated on October 5, 2022
Step 1: package installation
sudo apt install unattended-upgrades
This package may already be installed on your server.
Step 2: configure automatic updates
Edit the configuration file (here with nano – replace with any other text editor):
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
The beginning of the configuration file should look like this:
Anything after a double slash “
//” is a comment and has no effect. To “enable” a line, remove the double slash at the beginning of the line (replace with nothing or with spaces to keep alignment).
The most important: uncomment the “
updates” line by deleting the two slashes at the beginning of it:
Recommended: remove unused kernel packages and dependencies and make sure the system automatically reboots if needed by uncommenting and adapting the following lines:
↑ Ubuntu Server 18.04: You may have to add a semicolon at the end of this line. Fixed in 20.04. ↑
To save your changes in nano, use Ctrl + O followed by Enter. To quit, use Ctrl + X.
How to get email notification after automatic updates
Uncomment and adapt the following lines to ensure you’ll be notified if an error happens:
Step 3: enable automatic updates
Enable automatic updates and set up update intervals by running:
sudo nano /etc/apt/apt.conf.d/20auto-upgrades
In most cases, the file will be empty. In Ubuntu 22.04, the file has only two lines by default. Change or insert the following lines:
The time interval is specified in days, feel free to change the values. Save changes and exit.
Step 4: check if it works
You can see if the auto-upgrades work by launching a dry run:
sudo unattended-upgrades --dry-run --debug
The dry-run may output something like this:
Depending on your server configuration, the output may look less clean, which is OK:
Another way to check if automatic updates work is waiting a few days and checking the unattended upgrades logs:
Done! Ubuntu Server 18.04 / 20.04 / 22.04 should now update itself once a day.
This tutorial is based on the following article:
Ubuntu.com » Community Help Wiki » AutomaticSecurityUpdates
By Johannes Eva, April 2018 – October 2022