Linux
linuxlinuxGuideBeginner
Linux Package Management (apt, dnf, apk)
Install, update, upgrade, and manage operating system packages across Ubuntu/Debian (apt), RedHat/Fedora (dnf), and Alpine Linux (apk).
Verified: 2026-09-30
Tested on:linux Ubuntu 24.04 / Alpine 3.20
Platforms:
linux
#linux#package-manager#apt#dnf#apk#devops
Overview
Linux package managers download pre-compiled software binaries, resolve dependency trees, and handle automated security updates.
1. Debian & Ubuntu (apt)
# Update repository package metadata list
sudo apt update
# Upgrade all installed packages to latest versions
sudo apt upgrade -y
# Install new packages
sudo apt install -y curl git nginx build-essential
# Remove a package (keeps config files)
sudo apt remove nginx
# Purge package and all associated configuration files
sudo apt purge nginx
# Remove orphaned dependencies no longer needed
sudo apt autoremove -y
# Clean downloaded .deb cache
sudo apt clean2. RHEL / CentOS / Rocky / Fedora (dnf / yum)
# Check for updates and upgrade system
sudo dnf upgrade -y
# Install packages
sudo dnf install -y nginx git
# Remove package
sudo dnf remove -y nginx3. Alpine Linux (apk) (Docker Containers)
# Update package index and install without caching tarballs (keeps Docker image small)
apk update && apk add --no-cache curl ca-certificates bash
# Remove package
apk del curlCommand Quick Reference
| Action | Ubuntu/Debian (apt) | RHEL/Fedora (dnf) | Alpine (apk) |
|---|---|---|---|
| Update Index | apt update | dnf check-update | apk update |
| Upgrade System | apt upgrade | dnf upgrade | apk upgrade |
| Install Package | apt install <pkg> | dnf install <pkg> | apk add <pkg> |
| Remove Package | apt remove <pkg> | dnf remove <pkg> | apk del <pkg> |
| Search Package | apt search <term> | dnf search <term> | apk search <term> |
systemd & systemctl Service Management
Master systemctl commands, create production systemd service unit files, configure auto-restart policies, and manage background daemons.
Linux Disk Usage & Inode Management
Monitor disk partition capacity with df, inspect directory sizes with du, diagnose inode exhaustion, and reclaim disk space safely.