Back to Articles
Linux

Linux Package Management: Installing and Managing Software

Understanding RPM, YUM, DNF, APT, and Package Management Systems

Alex Lux2023-11-246 min read
LinuxPackage ManagementRPMYUMAPTDNF
Linux Package Management: Installing and Managing Software
Use this link for review flash cards

Linux Package Management: Installing and Managing Software

Package management is essential for installing, updating, and removing software on Linux systems. Different Linux distributions use different package managers: Red Hat-based systems use RPM, YUM, and DNF, while Debian-based systems use APT and dpkg. Understanding these tools is crucial for system administration.

Package Management Systems Overview

Red Hat-Based Systems

RPM (Red Hat Package Manager):

  • Low-level package manager
  • Handles individual .rpm package files
  • Used by YUM and DNF as backend

YUM (Yellowdog Updater Modified):

  • High-level package manager
  • Resolves dependencies automatically
  • Used in RHEL 6 and older CentOS

DNF (Dandified YUM):

  • Modern replacement for YUM
  • Better dependency resolution
  • Used in RHEL 8+, Fedora, newer CentOS

Debian-Based Systems

dpkg: Low-level package manager (like RPM)

APT (Advanced Package Tool):

  • High-level package manager
  • Resolves dependencies automatically
  • Used in Ubuntu, Debian

RPM Package Management

Basic RPM Commands

Install Package:

# Install from file
sudo rpm -i package.rpm

# Install with verbose output
sudo rpm -ivh package.rpm

Query Packages:

# List all installed packages
rpm -qa

# Query specific package
rpm -q package-name

# Show package information
rpm -qi package-name

# List files in package
rpm -ql package-name

# Show package file
rpm -qf /path/to/file

Remove Package:

# Remove package
sudo rpm -e package-name

# Remove with verbose output
sudo rpm -ev package-name

Verify Package:

# Verify package integrity
rpm -V package-name

# Verify all packages
rpm -Va

Common RPM Options:

  • -i: Install
  • -U: Upgrade
  • -e: Erase (remove)
  • -q: Query
  • -V: Verify
  • -v: Verbose
  • -h: Show hash marks
  • --nodeps: Ignore dependencies
  • --force: Force installation

YUM Package Management

YUM is the high-level package manager for older Red Hat-based systems.

Basic YUM Commands

Search and List:

# Search for packages
yum search keyword

# List available packages
yum list available

# List installed packages
yum list installed

# List all packages
yum list all

# Show package information
yum info package-name

Install Packages:

# Install package
sudo yum install package-name

# Install multiple packages
sudo yum install package1 package2

# Install from local file
sudo yum localinstall package.rpm

Update Packages:

# Update all packages
sudo yum update

# Update specific package
sudo yum update package-name

# Check for updates
yum check-update

Remove Packages:

# Remove package
sudo yum remove package-name

# Remove package and dependencies
sudo yum erase package-name

Repository Management:

# List repositories
yum repolist

# Enable repository
sudo yum-config-manager --enable repository-name

# Disable repository
sudo yum-config-manager --disable repository-name

Clean Cache:

# Clean all cache
sudo yum clean all

# Clean packages cache
sudo yum clean packages

DNF Package Management

DNF is the modern replacement for YUM with improved performance and dependency resolution.

Basic DNF Commands

Search and List:

# Search for packages
dnf search keyword

# List available packages
dnf list available

# List installed packages
dnf list installed

# Show package information
dnf info package-name

Install Packages:

# Install package
sudo dnf install package-name

# Install multiple packages
sudo dnf install package1 package2

# Install from local file
sudo dnf install ./package.rpm

Update Packages:

# Update all packages
sudo dnf update

# Update specific package
sudo dnf update package-name

# Check for updates
dnf check-update

Remove Packages:

# Remove package
sudo dnf remove package-name

# Remove package and unused dependencies
sudo dnf autoremove

Repository Management:

# List repositories
dnf repolist

# List all repositories (including disabled)
dnf repolist all

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

# Disable repository
sudo dnf config-manager --disable repository-name

Group Management:

# List package groups
dnf group list

# Install package group
sudo dnf group install "Development Tools"

# Remove package group
sudo dnf group remove "Development Tools"

APT Package Management

APT is used on Debian and Ubuntu systems.

Basic APT Commands

Update Package Lists:

# Update package lists
sudo apt update

# Update and upgrade
sudo apt upgrade

# Full system upgrade
sudo apt full-upgrade

Search and List:

# Search for packages
apt search keyword

# List available packages
apt list

# List installed packages
apt list --installed

# Show package information
apt show package-name

Install Packages:

# Install package
sudo apt install package-name

# Install multiple packages
sudo apt install package1 package2

# Install from .deb file
sudo apt install ./package.deb

Remove Packages:

# Remove package (keep config files)
sudo apt remove package-name

# Remove package and config files
sudo apt purge package-name

# Remove unused packages
sudo apt autoremove

Clean Cache:

# Clean package cache
sudo apt clean

# Clean partial downloads
sudo apt autoclean

dpkg Package Management

dpkg is the low-level package manager for Debian-based systems.

Basic dpkg Commands

Install Package:

# Install .deb file
sudo dpkg -i package.deb

# Install and fix dependencies
sudo dpkg -i package.deb
sudo apt-get install -f  # Fix broken dependencies

Query Packages:

# List installed packages
dpkg -l

# Show package information
dpkg -s package-name

# List files in package
dpkg -L package-name

# Find package owning file
dpkg -S /path/to/file

Remove Package:

# Remove package (keep config)
sudo dpkg -r package-name

# Remove package and config
sudo dpkg -P package-name

Repository Configuration

YUM/DNF Repositories

Repository Files: /etc/yum.repos.d/*.repo

Example .repo File:

[myrepo]
name=My Repository
baseurl=http://example.com/repo
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-myrepo

YUM Configuration: /etc/yum.conf

APT Repositories

Repository Files: /etc/apt/sources.list and /etc/apt/sources.list.d/*.list

Example sources.list Entry:

deb http://archive.ubuntu.com/ubuntu/ focal main restricted
deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted

APT Configuration: /etc/apt/apt.conf and /etc/apt/apt.conf.d/

Package Information and Queries

Finding Package Information

Which Package Provides a File:

# RPM/YUM/DNF
rpm -qf /path/to/file
dnf provides /path/to/file

# APT/dpkg
dpkg -S /path/to/file
apt-file search filename

Package Dependencies:

# RPM
rpm -qR package-name

# DNF
dnf deplist package-name

# APT
apt depends package-name

Package Contents:

# RPM
rpm -ql package-name

# dpkg
dpkg -L package-name

Acquiring Software

Downloading Packages

wget:

# Download file
wget http://example.com/package.rpm

# Continue interrupted download
wget -c http://example.com/package.rpm

# Download in background
wget -b http://example.com/package.rpm

curl:

# Download file
curl -O http://example.com/package.rpm

# Download with progress bar
curl -# -O http://example.com/package.rpm

# Download to specific file
curl -o package.rpm http://example.com/package.rpm

Building from Source

Extract Source:

tar -xzf source.tar.gz
cd source/

Build and Install:

./configure
make
sudo make install

Best Practices

Package Management

  1. Update Regularly: Keep package lists and system updated
  2. Use Repositories: Prefer repositories over manual package installation
  3. Verify Packages: Check package integrity and signatures
  4. Document Changes: Keep records of manually installed packages

Security

  1. Enable GPG Checks: Verify package signatures
  2. Use Trusted Repositories: Only use official or trusted repositories
  3. Update Security Patches: Apply security updates promptly
  4. Review Changes: Understand what packages do before installing

Troubleshooting

Common Issues

Broken Dependencies:

# YUM/DNF
sudo yum install -f
sudo dnf install -f

# APT
sudo apt install -f

Package Conflicts:

  • Review conflicting packages
  • Remove conflicting packages if necessary
  • Use --skip-broken (YUM) or --fix-broken (APT)

Repository Issues:

  • Verify repository URLs are accessible
  • Check network connectivity
  • Review repository configuration files
  • Clear cache and update

Conclusion

Package management is fundamental to Linux system administration. Whether using RPM/YUM/DNF on Red Hat-based systems or APT/dpkg on Debian-based systems, understanding how to install, update, and manage packages is essential. Each package manager has its strengths, but they all serve the same fundamental purpose: making software installation and management efficient and reliable.

By mastering package management tools, you can efficiently maintain software on Linux systems, resolve dependencies, and keep systems updated and secure. Regular updates and proper repository management ensure your systems remain stable and secure.

In the next article, we'll explore SSH and remote access, essential for secure remote system administration. Stay tuned!

Related Reading