How to enable unattended-upgrades in Ubuntu and Debian Linux

How to enable unattended-upgrades in Ubuntu and Debian Linux

Jack Wallen shows you how easy it is to enable unattended upgrades for both Ubuntu and Debian Linux so you can be sure to keep ahead of software updates.

Internet update button on computer keyboard
Image: cienpies/Adobe Stock

I run updates on my production machines every single day. Although there may not be updates for everything, it gives me a certain solace knowing I checked. I believe everyone who is serious about the privacy, security and behavior of their computers should do the same thing.

However, I also understand that life and work get in the way. This might be especially true if you have many machines to administer. Or you might have hundreds of users to tend to, and we all know how that can be.

SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium)

When life and users get in the way of you taking care of those tasks, what do you do to ensure those systems continue running smoothly and securely? Where there’s Linux, there’s a way.

With Debian and Ubuntu-based distributions, there’s a very easy way to set up unattended updates. In fact, it’s so easy you won’t believe it. That’s exactly what I’m going to show you how to do.

What you’ll need to enable unattended upgrades

The only things you’ll need for this are a running instance of a Debian or Ubuntu-based distribution and a user with sudo privileges. I’ll be demonstrating on Pop!_OS 22.04. With those two things at the ready, let’s make some Linux magic.

How to enable unattended upgrades

Log in to either your desktop or server. If you’re on a desktop variant, you’ll then need to open a terminal window. With the terminal window open, install the necessary software with:

sudo apt-get install unattended-upgrades -y

You may find, as I did with Ubuntu 22.10, that the software is already installed. However, that does not mean it’s configured to run. To do that, you need to use a different command.

How to set up unattended upgrades

Now, we need to configure the unattended upgrades. We’ll do this with a single command. What this command will do is set up unattended upgrades such that they’ll run at random times. The command for this is:

sudo dpkg-reconfigure -plow unattended-upgrades

Note: If you’re using Debian Linux, and your user isn’t a member of the sudo group, you might first have to change to the root user with the su command.

When you run the command, you’ll be presented with a choice. Make sure Yes is selected and hit Enter. If Yes isn’t selected, hit Tab or your left arrow key until it is and then hit Enter on your keyboard.

Obviously, what this does is only download and install important updates. Should you wish to get a bit more specific with those upgrades, open the configuration file with:

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

In that file, you’ll notice a section of lines that looks like this:

//      "${distro_id}:${distro_codename}-updates";
//      "${distro_id}:${distro_codename}-proposed";
//      "${distro_id}:${distro_codename}-backports";

Every line that starts with // is commented out. If you want to enable the updates associated with those lines, simply remove the // characters then save and close the file.

Another configuration file determines how often updates are run. That file is /etc/apt/apt.conf.d/20auto-upgrades. If you look in that file, you’ll see two lines like this:

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

The "1" indicates those updates are run every day. You could also add an auto-clean entry that will clean up apt every 7 days like this:

APT::Periodic::AutocleanInterval "7";

You can change the numerical figure to whatever you need. Save and close the file.

That’s all you need to do to enable unattended upgrades for a Debian or Ubuntu-based distribution. Take care of this and it will take care of you.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

Source of Article