LUNAROPS · OPERATIONAL UPLINK 100% UPTIME 1,247d POSTS 893 JEFF.MOON@LUNAROPS.DEV UTC --:--:--

Linux Package Management: apt, yum, and Beyond

linuxpackagesaptyumdnf

Package managers handle installing, updating, and removing software. Different Linux families use different tools, but the concepts are similar.

Package Manager Overview

Distribution Package Format Package Manager
Debian, Ubuntu .deb apt, dpkg
RHEL, CentOS, Fedora .rpm dnf/yum, rpm
Arch .pkg.tar.zst pacman
Alpine .apk apk
SUSE .rpm zypper

APT (Debian/Ubuntu)

Update Package Lists

1
2
3
4
5
6
7
8
# Update available package info
sudo apt update

# Upgrade installed packages
sudo apt upgrade

# Full upgrade (handles dependencies)
sudo apt full-upgrade

Installing Packages

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Install single package
sudo apt install nginx

# Install multiple packages
sudo apt install nginx postgresql redis

# Install specific version
sudo apt install nginx=1.18.0-0ubuntu1

# Install without prompts
sudo apt install -y nginx

Removing Packages

1
2
3
4
5
6
7
8
# Remove package (keep config)
sudo apt remove nginx

# Remove package and config
sudo apt purge nginx

# Remove unused dependencies
sudo apt autoremove

Searching

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Search by name
apt search nginx

# Show package info
apt show nginx

# List installed packages
apt list --installed

# List upgradable packages
apt list --upgradable

Cache Management

1
2
3
4
5
# Clean package cache
sudo apt clean

# Remove old package versions
sudo apt autoclean

dpkg (Low-Level)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Install .deb file
sudo dpkg -i package.deb

# List installed packages
dpkg -l

# Find which package owns a file
dpkg -S /usr/bin/nginx

# List files in package
dpkg -L nginx

DNF/YUM (RHEL/Fedora)

DNF is the modern replacement for YUM. Commands are mostly compatible.

Basic Operations

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Update package lists and upgrade
sudo dnf upgrade

# Install package
sudo dnf install nginx

# Remove package
sudo dnf remove nginx

# Search packages
dnf search nginx

# Package info
dnf info nginx

Groups

1
2
3
4
5
# List groups
dnf group list

# Install group
sudo dnf group install "Development Tools"

Repository Management

1
2
3
4
5
6
7
8
# List repos
dnf repolist

# Enable repo
sudo dnf config-manager --enable repo-name

# Add repo
sudo dnf config-manager --add-repo https://example.com/repo.repo

History and Rollback

1
2
3
4
5
6
7
8
# View history
dnf history

# Undo last transaction
sudo dnf history undo last

# Undo specific transaction
sudo dnf history undo 42

rpm (Low-Level)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Install .rpm file
sudo rpm -ivh package.rpm

# Query installed packages
rpm -qa

# Find package owning file
rpm -qf /usr/bin/nginx

# List files in package
rpm -ql nginx

Pacman (Arch)

Basic Operations

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Update system
sudo pacman -Syu

# Install package
sudo pacman -S nginx

# Remove package
sudo pacman -R nginx

# Remove with dependencies
sudo pacman -Rs nginx

# Search packages
pacman -Ss nginx

# Package info
pacman -Si nginx

Query Installed

1
2
3
4
5
6
7
8
# List installed packages
pacman -Q

# Find package owning file
pacman -Qo /usr/bin/nginx

# List orphaned packages
pacman -Qdt

Clean Cache

1
2
3
4
5
# Remove old package versions
sudo pacman -Sc

# Remove all cached packages
sudo pacman -Scc

APK (Alpine)

Alpine is popular in containers due to its small size.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Update and upgrade
apk update
apk upgrade

# Install package
apk add nginx

# Remove package
apk del nginx

# Search
apk search nginx

# Package info
apk info nginx

# List installed
apk list --installed

Common Tasks Across Distros

Update Everything

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Debian/Ubuntu
sudo apt update && sudo apt upgrade -y

# RHEL/Fedora
sudo dnf upgrade -y

# Arch
sudo pacman -Syu

# Alpine
apk update && apk upgrade

Install Build Tools

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Debian/Ubuntu
sudo apt install build-essential

# RHEL/Fedora
sudo dnf group install "Development Tools"

# Arch
sudo pacman -S base-devel

# Alpine
apk add build-base

Find Package for Command

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Debian/Ubuntu
apt-file search /usr/bin/htop
# or
sudo apt install apt-file
apt-file update
apt-file search htop

# RHEL/Fedora
dnf provides /usr/bin/htop

# Arch
pacman -F htop

Adding Repositories

Ubuntu PPA

1
2
3
4
5
6
7
8
# Add PPA
sudo add-apt-repository ppa:user/repo

# Remove PPA
sudo add-apt-repository --remove ppa:user/repo

# Update after adding
sudo apt update

Manual Repository (Debian/Ubuntu)

1
2
3
4
5
6
7
8
9
# Add GPG key
curl -fsSL https://example.com/key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/example.gpg

# Add repository
echo "deb [signed-by=/etc/apt/keyrings/example.gpg] https://example.com/repo stable main" | \
  sudo tee /etc/apt/sources.list.d/example.list

# Update
sudo apt update

RHEL/Fedora Repository

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Add repo file
sudo dnf config-manager --add-repo https://example.com/repo.repo

# Or create manually
cat <<EOF | sudo tee /etc/yum.repos.d/example.repo
[example]
name=Example Repository
baseurl=https://example.com/repo
enabled=1
gpgcheck=1
gpgkey=https://example.com/key.gpg
EOF

Comparing Package Managers

Task apt dnf pacman apk
Update lists apt update dnf check-update pacman -Sy apk update
Upgrade all apt upgrade dnf upgrade pacman -Syu apk upgrade
Install apt install X dnf install X pacman -S X apk add X
Remove apt remove X dnf remove X pacman -R X apk del X
Search apt search X dnf search X pacman -Ss X apk search X
Info apt show X dnf info X pacman -Si X apk info X
Clean cache apt clean dnf clean all pacman -Sc apk cache clean

Tips

Pin Package Version

Prevent automatic upgrades:

1
2
3
4
5
# Debian/Ubuntu
sudo apt-mark hold nginx

# Release hold
sudo apt-mark unhold nginx

List Security Updates

1
2
3
4
5
# Debian/Ubuntu
sudo apt list --upgradable 2>/dev/null | grep -i security

# RHEL
sudo dnf updateinfo list security

Check Package Before Install

1
2
3
# Simulate installation
sudo apt install --dry-run nginx
sudo dnf install --assumeno nginx

Package managers make software management safe and consistent. Learn your distro’s package manager well—it’s the primary way you’ll interact with software.

Comments