Skip to content

Package Management

Overview

Package management is one of the core tasks in Linux system administration. Different distributions use different package management systems; this chapter introduces the main package management tools.

Package Management System Comparison

DistributionPackage FormatLow-level ToolHigh-level Tool
Debian/Ubuntu.debdpkgapt, apt-get
RHEL/Fedora.rpmrpmdnf, yum
Arch Linux.pkg.tar.zstpacmanpacman
openSUSE.rpmrpmzypper

APT (Debian/Ubuntu)

Update Software Sources

bash
# Update package list
$ sudo apt update

# Upgrade all packages
$ sudo apt upgrade

# Upgrade with dependency changes
$ sudo apt full-upgrade

# Update and upgrade together
$ sudo apt update && sudo apt upgrade -y

Search for Software

bash
# Search for package
$ apt search nginx
$ apt search python

# Show package information
$ apt show nginx

# List installed packages
$ apt list --installed

# List upgradable packages
$ apt list --upgradable

Install Software Packages

bash
# Install package
$ sudo apt install nginx

# Install multiple packages
$ sudo apt install nginx php mysql-server

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

# Install local .deb file
$ sudo apt install ./package.deb

# Reinstall
$ sudo apt reinstall nginx

Remove Software Packages

bash
# Remove package (keep configuration)
$ sudo apt remove nginx

# Remove package and configuration
$ sudo apt purge nginx

# Remove unused dependencies
$ sudo apt autoremove

# Clean downloaded package files
$ sudo apt clean
$ sudo apt autoclean

Software Source Configuration

Software source configuration file: /etc/apt/sources.list

bash
# View software sources
$ cat /etc/apt/sources.list

# Add PPA (Ubuntu)
$ sudo add-apt-repository ppa:user/ppa-name
$ sudo apt update

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

dpkg - Low-level Package Management

bash
# Install .deb package
$ sudo dpkg -i package.deb

# Fix dependency issues
$ sudo apt install -f

# Remove package
$ sudo dpkg -r package_name

# List installed packages
$ dpkg -l
$ dpkg -l | grep nginx

# Show package information
$ dpkg -s nginx

# List package's files
$ dpkg -L nginx

# Find which package a file belongs to
$ dpkg -S /usr/sbin/nginx

DNF/YUM (Fedora/RHEL)

Update Software

bash
# Check for updates
$ sudo dnf check-update

# Upgrade all packages
$ sudo dnf upgrade
$ sudo dnf update

# Upgrade specific package
$ sudo dnf upgrade nginx

Search and Install

bash
# Search for package
$ dnf search nginx

# Show package information
$ dnf info nginx

# Install package
$ sudo dnf install nginx

# Install local rpm
$ sudo dnf install ./package.rpm

# Install group
$ sudo dnf groupinstall "Development Tools"

Remove Software Packages

bash
# Remove package
$ sudo dnf remove nginx

# Remove unused dependencies
$ sudo dnf autoremove

# Clean cache
$ sudo dnf clean all

rpm - Low-level Package Management

bash
# Install rpm package
$ sudo rpm -ivh package.rpm

# Upgrade rpm package
$ sudo rpm -Uvh package.rpm

# Remove package
$ sudo rpm -e package_name

# Query installed packages
$ rpm -qa
$ rpm -qa | grep nginx

# Query package information
$ rpm -qi nginx

# List package's files
$ rpm -ql nginx

# Find which package a file belongs to
$ rpm -qf /usr/sbin/nginx

Software Source Configuration

bash
# Source configuration directory
$ ls /etc/yum.repos.d/

# Add EPEL source
$ sudo dnf install epel-release

# List enabled sources
$ dnf repolist

# List all sources
$ dnf repolist all

Pacman (Arch Linux)

Sync and Update

bash
# Sync package database
$ sudo pacman -Sy

# Upgrade all packages
$ sudo pacman -Su

# Sync and upgrade
$ sudo pacman -Syu

Search and Install

bash
# Search for package
$ pacman -Ss nginx

# Show package information
$ pacman -Si nginx

# Install package
$ sudo pacman -S nginx

# Install local package
$ sudo pacman -U package.pkg.tar.zst

Remove Software Packages

bash
# Remove package
$ sudo pacman -R nginx

# Remove package and dependencies
$ sudo pacman -Rs nginx

# Remove package, dependencies, and configuration
$ sudo pacman -Rns nginx

# Clean cache
$ sudo pacman -Sc

Query

bash
# List installed packages
$ pacman -Q
$ pacman -Q | grep nginx

# Query installed package info
$ pacman -Qi nginx

# List package's files
$ pacman -Ql nginx

# Find which package a file belongs to
$ pacman -Qo /usr/sbin/nginx

Universal Tools

snap

bash
# Install snap
$ sudo apt install snapd

# Search snap packages
$ snap find package

# Install snap package
$ sudo snap install package

# List installed snaps
$ snap list

# Update snap packages
$ sudo snap refresh

# Remove snap package
$ sudo snap remove package

flatpak

bash
# Install flatpak
$ sudo apt install flatpak

# Add Flathub
$ flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

# Search for applications
$ flatpak search application

# Install application
$ flatpak install flathub com.example.App

# Run application
$ flatpak run com.example.App

# List installed
$ flatpak list

# Remove application
$ flatpak uninstall com.example.App

AppImage

bash
# AppImage is an executable file, no installation needed
$ chmod +x app.AppImage
$ ./app.AppImage

Compile from Source

Typical Steps

bash
# 1. Download source code
$ wget https://example.com/software.tar.gz
$ tar xzf software.tar.gz
$ cd software

# 2. Configure
$ ./configure --prefix=/usr/local

# 3. Compile
$ make

# 4. Install
$ sudo make install

Install Compilation Tools

bash
# Debian/Ubuntu
$ sudo apt install build-essential

# Fedora
$ sudo dnf groupinstall "Development Tools"

# Arch Linux
$ sudo pacman -S base-devel

checkinstall

Create manageable package:

bash
# Install checkinstall
$ sudo apt install checkinstall

# Use checkinstall instead of make install
$ sudo checkinstall
# This creates .deb package and installs it

Practical Tips

View Installed Software Size

bash
# Debian/Ubuntu
$ dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -20

# Arch Linux
$ pacman -Qi | awk '/^Name/{name=$3} /^Installed Size/{print $4$5, name}' | sort -h | tail -20

List Manually Installed Packages

bash
# Debian/Ubuntu
$ apt-mark showmanual

# Arch Linux
$ pacman -Qe

Fix Broken Packages

bash
# Debian/Ubuntu
$ sudo apt --fix-broken install
$ sudo dpkg --configure -a

# Fedora
$ sudo dnf distro-sync

Lock Package Versions

bash
# Debian/Ubuntu
$ sudo apt-mark hold package_name
$ sudo apt-mark unhold package_name

# View locked packages
$ apt-mark showhold

Clean System

bash
# Debian/Ubuntu
$ sudo apt autoremove
$ sudo apt autoclean
$ sudo apt clean

# Remove old kernels (Ubuntu)
$ sudo apt autoremove --purge

Summary

This chapter introduced Linux package management:

  • APT (Debian/Ubuntu): apt, dpkg
  • DNF/YUM (Fedora/RHEL): dnf, rpm
  • Pacman (Arch): pacman
  • Universal formats: snap, flatpak, AppImage
  • Compile from source: configure, make, install

Choose appropriate package management method and keep your system clean and secure.


Previous chapter: Process Management

Next chapter: Service Management

Content is for learning and research only.