What is APT ?
On this page
APT which stands for Advanced Package Tool is the Linux package management system. APT is what keeps a server secure, up-to-date, and consistent with the latest patches and features.
It’s responsible for:
- Installing new software with
apt install - Updating existing packages with
apt upgrade - Removing software with
apt remove - Managing package dependencies
The goal of this lesson is to configure a server to automatically download and install software updates without manual intervention.
Step 1: Install the Required Packages
Install unattended-upgrades and apt-listchanges.
apt update
apt install -y unattended-upgrades apt-listchangesStep 2: Enable Auto Upgrades
Create and edit the configuration file.
nano /etc/apt/apt.conf.d/20auto-upgradesWhat this does:
- nano = creates file and then opens it in nano editor
File Contents for /etc/apt/apt.conf.d/20auto-upgrades.
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";What this does:
- Update-Package-Lists = update
aptdatabase daily - Download-Upgradeable-Packages = download available packages daily
- AutocleanInterval = remove old packages after 7 days
- Unattended-Upgrade = actually install updates automatically
Step 3: Configure Packages to Auto Upgrade
Edit the main config file.
nano /etc/apt/apt.conf.d/50unattended-upgradesMake sure the following lines are uncommented.
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";
};Step 4: Enable and test the service
Enable unattended_upgrades.
dpkg-reconfigure --priority=low unattended-upgradesWhen prompted click yes.
Check if unattended-upgrades is active (running).
systemctl enable unattended-upgrades
systemctl start unattended-upgrades
systemctl status unattended-upgradesWhat this does:
- systemctl enable = configures the service to start on system boot
- systemctl start = starts the service
- systemctl status = shows the current status of the service, displays running, stopped, or failed
- You should see that
unattended-upgradesis active (running)
Test that everything works manually using a dry run.
unattended-upgrade --dry-run --debugWhat this does:
- This simulates an upgrade without actually installing anything
- You should see a list of packages that would be installed