Keeping your Ubuntu 22.04 system updated is essential to ensure security and performance. Manually updating the system can be time-consuming, and you may forget to do it regularly. This blog post will guide you on how to set up automatic OS package updates using the unattended-upgrades
package, ensuring your system stays up-to-date with minimal effort.
Step 1: Install the unattended-upgrades
package
First, update the package list and install the unattended-upgrades
package by running the following commands:
sudo apt update
sudo apt install unattended-upgrades
Step 2: Enable the unattended-upgrades service
Activate the service by executing the command below:
sudo dpkg-reconfigure --priority=low unattended-upgrades
This will create a configuration file at /etc/apt/apt.conf.d/50unattended-upgrades
. The default settings should be sufficient for most users, but you can customize the configuration if needed.
Step 3: Configure automatic updates
To edit the configuration file, open it with a text editor:
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
By default, only security updates are enabled. If you want to enable automatic updates for all packages, find and uncomment the following lines:
// "${distro_id}:${distro_codename}";
// "${distro_id}:${distro_codename}-updates";
Uncomment the lines by removing the //
at the beginning of each line.
You can also configure other options, such as update frequency, reboot allowances, and more. Make sure to read the comments in the file to understand each setting.
Save and exit the text editor (Ctrl + X, then Y, and press Enter in nano).
Step 4: Configure update frequency
Adjust the frequency of automatic updates by editing the /etc/apt/apt.conf.d/20auto-upgrades
file:
sudo nano /etc/apt/apt.conf.d/20auto-upgrades
Modify the settings as desired. For example, if you want to update the package list and perform unattended upgrades weekly, change the “1” to “7” for both Update-Package-Lists
and Unattended-Upgrade
.
Save and exit the text editor.
Step 5: Restart the unattended-upgrades
service
Apply the changes by restarting the unattended-upgrades
service:
sudo systemctl restart unattended-upgrades
Conclusion:
With these simple steps, you have configured your Ubuntu 22.04 system to automatically update OS packages based on your preferences. This will ensure your system remains secure and up-to-date without the need for manual intervention.