Automatic updates of your linux system

One of the no. 1 things we recommend is keeping your operating system up to date!
The means to automate the process is pretty straight forward.
This procedure is pretty much the same for Ubuntu or Debian :smile:

Step 1: package installation

Install the unattended-upgrades package:
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:

Install unattended upgrades on Ubuntu Server

Anything after a double slash β€œ // ” is a comments 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:
"${distro_id}:${distro_codename}-updates";

Optional: You should uncomment and adapt the following lines to ensure you’ll be notified if an error happens:
Unattended-Upgrade::Mail "[email protected]";
Unattended-Upgrade::MailOnlyOnError "true";

Recommended: remove unused kernel packages and dependencies and make sure the system automatically reboots if needed by uncommenting and adapting the following lines:
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
↑ You may have to add a semicolon at the end of this line. ↑
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Optional:
Unattended-Upgrade::Automatic-Reboot "true";Unattended-Upgrade::Automatic-Reboot-Time "02:38";

To save your changes in nano , use Ctrl + O followed by Enter. To quit, use Ctrl + X.

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. Copy and paste the following lines:

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

The time interval are 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 should output something like this:

Unattended upgrades on Ubuntu Server 18.04 Bionic Beaver

Another way to check if automatic updates work is waiting a few days and checking the unattended upgrades logs:
cat /var/log/unattended-upgrades/unattended-upgrades.log

Done! Ubuntu Server 18.04 should now update itself once a day.
1 Like

once in a while when I do an update (manually) it asks if I want to keep old or install new and I go with keep old as I have this vague idea that it actually relates to prefs and they would be needed for the box to work. But what about those pop up questions what will happen or are they excluded from the unattended updates or will it cause for it to send me an email as an error or or or ? hehe

Typically in cases such as this it will opt for the default options, which is to keep the old.

2 Likes