Ubuntu: Automatically install updates

Ubuntu: Automatically install updates

April 23, 2025 Configuration Linux Server System Administration 0

Ubuntu has a built-in mechanism for automatic security updates. You can enable it as follows:

  1. Open a terminal.
  2. Run the following command to install the unattended-upgrades package if it’s not already installed:
sudo apt-get install unattended-upgrades
  1. 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:

  1. Open the unattended-upgrades configuration file:
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
  1. 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).

  1. 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";
  1. Save the changes and close the file.

⏱️ Set Automatic Update Interval

You can also configure how frequently the system checks for updates:

  1. Open the file /etc/apt/apt.conf.d/20auto-upgrades:
sudo nano /etc/apt/apt.conf.d/20auto-upgrades
  1. 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:

  1. Open the /etc/apt/apt.conf.d/50unattended-upgrades file again:
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
  1. Look for:
Unattended-Upgrade::Automatic-Reboot "false";
  1. Change false to true to enable automatic reboots:
Unattended-Upgrade::Automatic-Reboot "true";
  1. Save the changes.

With these settings, Ubuntu will automatically download and install updates based on your configured parameters.