Configure Linux package management with apt, dnf and yum for system updates

Beginner 25 min Apr 17, 2026 22 views
Ubuntu 24.04 Ubuntu 22.04 Debian 12 AlmaLinux 9 Rocky Linux 9 Fedora 41

Learn to manage Linux packages effectively with apt, dnf, and yum across Ubuntu, Debian, and RHEL-based distributions. Master installation, updates, repository management, and troubleshooting for reliable system maintenance.

Prerequisites

  • Root or sudo access
  • Active internet connection

What this solves

Linux package managers handle software installation, updates, and dependency resolution across different distributions. Understanding apt (Ubuntu/Debian), dnf (Fedora/newer RHEL), and yum (older RHEL systems) ensures you can maintain secure, up-to-date systems regardless of your distribution choice.

Understanding Linux package managers

Package managers automate software installation by handling dependencies, version conflicts, and system integration. Each distribution family uses different tools but follows similar principles.

DistributionPackage ManagerPackage FormatRepository Config
Ubuntu/Debianapt.deb/etc/apt/sources.list
Fedora/RHEL 8+dnf.rpm/etc/yum.repos.d/
CentOS 7/RHEL 7yum.rpm/etc/yum.repos.d/
Note: dnf is the modern replacement for yum. RHEL 8+ and Fedora use dnf, while older systems still use yum. The commands are largely identical.

Step-by-step configuration

Update package databases

Always start by refreshing your package manager's database to ensure you get the latest package versions and security updates.

sudo apt update
sudo apt list --upgradable
sudo dnf check-update
sudo dnf list --updates

Upgrade system packages

Apply available updates to keep your system secure and stable. This updates all installed packages to their latest versions.

sudo apt upgrade -y
sudo apt full-upgrade -y
sudo dnf upgrade -y
Note: full-upgrade on apt removes packages if needed for upgrades, while upgrade is more conservative.

Install new packages

Install software packages with automatic dependency resolution. This example installs common system monitoring tools.

sudo apt install -y htop curl wget git vim
sudo apt install --no-install-recommends nginx
sudo dnf install -y htop curl wget git vim
sudo dnf install --setopt=install_weak_deps=False nginx

Search for packages

Find available packages before installation using search functionality.

apt search nginx
apt show nginx
apt list --installed | grep nginx
dnf search nginx
dnf info nginx
dnf list installed | grep nginx

Remove packages

Uninstall packages cleanly, with options to remove configuration files and unused dependencies.

sudo apt remove package-name
sudo apt purge package-name
sudo apt autoremove
sudo dnf remove package-name
sudo dnf autoremove

Package repository management

View configured repositories

Check which repositories your system uses for package installation.

cat /etc/apt/sources.list
ls /etc/apt/sources.list.d/
apt policy
dnf repolist
dnf repolist all
ls /etc/yum.repos.d/

Add external repositories

Add third-party repositories for additional software packages. This example adds the official Docker repository.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt update
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf makecache

Manage repository GPG keys

Repository GPG keys ensure package authenticity and prevent tampering.

apt-key list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys KEY_ID
apt-key finger
rpm -qa gpg-pubkey*
sudo rpm --import /path/to/key.gpg
dnf repolist -v
Security note: Always verify GPG key fingerprints against official documentation before importing keys.

Advanced package operations

Hold packages from updates

Prevent specific packages from being automatically updated, useful for maintaining compatibility.

sudo apt-mark hold nginx
apt-mark showhold
sudo apt-mark unhold nginx
sudo dnf versionlock add nginx
dnf versionlock list
sudo dnf versionlock delete nginx

Install specific package versions

Install or downgrade to specific package versions when needed for compatibility.

apt list -a nginx
sudo apt install nginx=1.18.0-6ubuntu14.4
apt-cache policy nginx
dnf list --showduplicates nginx
sudo dnf install nginx-1.20.1-1.el9
dnf info nginx

Clean package cache

Free disk space by cleaning downloaded package files and metadata.

sudo apt clean
sudo apt autoclean
du -sh /var/cache/apt/archives/
sudo dnf clean all
sudo dnf clean packages
du -sh /var/cache/dnf/

Automated updates and security

Configure automatic security updates

Enable automatic installation of security patches to keep your system secure without manual intervention.

sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
sudo dnf install -y dnf-automatic
sudo systemctl enable --now dnf-automatic.timer

Configure automatic update settings

Customize which updates get installed automatically and notification preferences.

Unattended-Upgrade::Allowed-Origins {
    "${distro_id}:${distro_codename}-security";
    "${distro_id} ESMApps:${distro_codename}-apps-security";
    "${distro_id} ESM:${distro_codename}-infra-security";
};
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::Automatic-Reboot "false";
[commands]
upgrade_type = security
random_sleep = 0
download_updates = yes
apply_updates = yes

[emitters]
system_name = example.com
emit_via = email
email_from = root@example.com
email_to = admin@example.com

Verify your setup

Check that your package management system is working correctly and configured properly.

sudo apt update && apt list --upgradable
sudo systemctl status unattended-upgrades
ls -la /var/log/unattended-upgrades/

For dnf/yum systems:

sudo dnf check-update
sudo systemctl status dnf-automatic.timer
journalctl -u dnf-automatic.service

You can also integrate this with system monitoring tools like process monitoring with htop and service management with systemctl for comprehensive system oversight.

Troubleshooting common package issues

SymptomCauseFix
Package has unmet dependenciesBroken package relationshipssudo apt --fix-broken install or sudo dnf distro-sync
Hash Sum mismatch errorsCorrupt package cachesudo apt clean && sudo apt update
Repository not foundInvalid repository URL or missing GPG keyCheck /etc/apt/sources.list or remove invalid repo
Package locked by another processMultiple package managers runningWait for other process to finish or kill if hung
Disk space errors during installFull filesystemsudo apt autoremove && sudo apt autoclean
GPG signature verification failedMissing or expired repository keyImport correct GPG key from official source

Next steps

Running this in production?

Want this handled for you? This works for a single server. When you run multiple environments or need this available 24/7, keeping it healthy is a different job. See how we run infrastructure like this for European teams.

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed cloud infrastructure for businesses that depend on uptime. From initial setup to ongoing operations.