Operations 8 min read

Master Linux Package Managers: apt, yum, dnf, pacman, zypper

This guide explains how to use the major Linux package managers—apt, yum, dnf, pacman, and zypper—to update repositories, install, upgrade, and remove software, as well as advanced tasks like searching, viewing package info, handling transactions, configuring repositories, and troubleshooting common issues.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Package Managers: apt, yum, dnf, pacman, zypper

APT Package Manager (Debian/Ubuntu)

Refresh the local package index so the system knows about the latest versions available in the configured repositories. sudo apt update Install a specific package (e.g., Visual Studio Code). sudo apt install code Upgrade all installed packages to the newest versions. sudo apt upgrade Remove a package while also deleting its configuration files.

sudo apt remove code

YUM Package Manager (Red Hat/CentOS)

Update the repository metadata. sudo yum update Install a package (e.g., nginx). sudo yum install nginx Upgrade all installed packages. sudo yum upgrade Remove a package.

sudo yum remove nginx

DNF Package Manager (Fedora)

Refresh the repository metadata. sudo dnf update Install a package (e.g., git). sudo dnf install git Upgrade all installed packages. sudo dnf upgrade Remove a package.

sudo dnf remove git

Pacman Package Manager (Arch Linux)

Synchronize the package database with remote mirrors. sudo pacman -Sy Install a package (e.g., vim). sudo pacman -S vim Perform a full system upgrade, including dependency resolution. sudo pacman -Syu Remove a package and its unneeded dependencies.

sudo pacman -Rns vim

Zypper Package Manager (openSUSE)

Refresh repository metadata. sudo zypper refresh Install a package (e.g., firefox). sudo zypper install firefox Upgrade all installed packages. sudo zypper update Remove a package.

sudo zypper remove firefox

Advanced Package‑Manager Operations

Search for Packages

# Debian/Ubuntu
apt search nginx
# Red Hat/CentOS
yum search nginx
# Arch Linux
pacman -Ss nginx

Show Package Information

# Debian/Ubuntu
apt show nginx
# Red Hat/CentOS
yum info nginx
# Arch Linux
pacman -Si nginx

List Installed Packages

# Debian/Ubuntu
dpkg -l
# Red Hat/CentOS
rpm -qa
# Arch Linux
pacman -Q

List Files Belonging to a Package

# Debian/Ubuntu
dpkg -L nginx
# Red Hat/CentOS
rpm -ql nginx
# Arch Linux
pacman -Ql nginx

Using Software Repositories

Switching Mirrors (Arch Linux Example)

# Backup current mirrorlist
sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
# Download a fresh list of mirrors
sudo curl -o /etc/pacman.d/mirrorlist https://archlinux.org/mirrorlist/all/
# Uncomment Server lines
sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist
# Keep the top 6 fastest mirrors
rankmirrors -n 6 /etc/pacman.d/mirrorlist | sudo tee /etc/pacman.d/mirrorlist
# Refresh the package database
sudo pacman -Sy

Adding a PPA (Ubuntu Example)

# Add the nginx stable PPA
sudo add-apt-repository ppa:nginx/stable
# Update the package index
sudo apt update
# Install nginx from the new source
sudo apt install nginx

Troubleshooting and Repair

Repair Broken Packages

# Debian/Ubuntu
sudo apt install --reinstall package_name
# Red Hat/CentOS
sudo yum reinstall package_name
# Arch Linux
sudo pacman -S package_name

Resolve Dependency Issues

# Debian/Ubuntu – attempt to fix missing dependencies
sudo apt install -f
# Red Hat/CentOS – utilities for cleaning and fixing problems
sudo yum install yum-utils
sudo package-cleanup --problems
sudo package-cleanup --dupes
sudo yum clean all
sudo yum update
# Arch Linux – full system upgrade also resolves most dependency conflicts
sudo pacman -Syu
LinuxAPTPackage Managementdnfyumpacmanzypper
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.