How to Set Up Automatic Updates on Ubuntu 22.04.4 LTS
How to Set Up Automatic Updates on Ubuntu 22.04.4 LTS
I don't set up servers often, but this is always something I need to find, so I'm leaving this here for me, for later. In fact I might turn this in to a GIST later for feedback.
The idea of this to to help set up Ubuntu 22.04.4 LTS, to ensure all critical updates are installed without manual intervention using the unattended-upgrades
package.
Step 1: Install Unattended Upgrades
First, ensure the unattended-upgrades
package is installed. Open a terminal and run:
sudo apt update && sudo apt install unattended-upgrades
Step 2: Enable Unattended Upgrades
Next, enable automatic updates by running the following command with high priority for a quicker setup:
sudo dpkg-reconfigure --priority=high unattended-upgrades
Why Choose "High" Priority?
Choosing the "high" priority setting simplifies the configuration process by focusing on essential settings. This is useful if you want to quickly enable automatic updates without being prompted to much. Might not be for everyone one, but works for me.
Step 3: Configure Unattended Upgrades
To fine-tune which updates are installed, edit the configuration file:
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
In this file, locate the Unattended-Upgrade::Allowed-Origins
section. By default, it might look like this:
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
// "${distro_id}:${distro_codename}-updates";
// "${distro_id}:${distro_codename}-proposed";
// "${distro_id}:${distro_codename}-backports";
};
Uncomment the lines for -updates
and -backports
to include these in your automatic updates:
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
"${distro_id}:${distro_codename}-updates";
"${distro_id}:${distro_codename}-backports";
};
Step 4: Configure the Update Interval
Edit the 20auto-upgrades
file to set how frequently the system checks for updates:
sudo nano /etc/apt/apt.conf.d/20auto-upgrades
Add or modify the following lines:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";
Update-Package-Lists "1";
– Update the package list daily.Download-Upgradeable-Packages "1";
– Download package updates daily.AutocleanInterval "7";
– Clean up old packages every 7 days.Unattended-Upgrade "1";
– Install updates daily.
Step 5: Verify the Configuration
Run a dry-run to ensure your configuration is correct:
sudo unattended-upgrades --dry-run --debug
This setup ensures your Ubuntu system remains secure and efficient by automatically applying the latest updates without requiring manual intervention. Happy updating!