Ubuntu: Automatically install updates
Ubuntu has a built-in mechanism for automatic security updates. You can enable it as follows:
- Open a terminal.
- Run the following command to install the unattended-upgrades package if it’s not already installed:
sudo apt-get install unattended-upgrades
- Configure the system to allow automatic updates:
sudo dpkg-reconfigure --priority=low unattended-upgrades
This will open a configuration screen where you can enable automatic security updates.
🔄 Enable Automatic Updates for All Packages
If you also want to enable automatic updates for all other packages, you’ll need to modify the configuration files:
- Open the unattended-upgrades configuration file:
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
- Look for the line:
"${distro_id}:${distro_codename}-updates";
Make sure it’s not commented out (i.e., it shouldn’t have //
in front of it).
- To allow automatic removal of unused packages, add the following line (or uncomment it if it’s already present):
Unattended-Upgrade::Remove-Unused-Dependencies "true";
- Save the changes and close the file.
⏱️ Set Automatic Update Interval
You can also configure how frequently the system checks for updates:
- Open the file
/etc/apt/apt.conf.d/20auto-upgrades
:
sudo nano /etc/apt/apt.conf.d/20auto-upgrades
- Adjust or add the following settings to configure daily updates:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";
Setting values to "1"
configures daily checks. You can change the numbers to match your preferences.
🔁 Optional: Configure Automatic Reboots
You can also configure the system to automatically reboot after installing updates:
- Open the
/etc/apt/apt.conf.d/50unattended-upgrades
file again:
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
- Look for:
Unattended-Upgrade::Automatic-Reboot "false";
- Change
false
totrue
to enable automatic reboots:
Unattended-Upgrade::Automatic-Reboot "true";
- Save the changes.
With these settings, Ubuntu will automatically download and install updates based on your configured parameters.