Skip to main content

Linux Package Management

 Package Management: The Linux Software Store

Learn how to install, update, and manage software packages like a professional Linux administrator.

📅 Published: Feb 2026
⏱️ Estimated Reading Time: 16 minutes
🏷️ Tags: Package Management, APT, YUM, DNF, Linux Software, DevOps


📦 Introduction to Package Managers: Your Software Installer

What is a Package Manager?

Think of a package manager as Linux's app store. Just like your phone has Google Play or Apple's App Store, Linux has package managers to help you find, install, update, and remove software. But Linux package managers are much more powerful than phone app stores!

A package manager does four main things:

  1. Downloads software from online repositories (like shopping in an app store)

  2. Handles dependencies - automatically installs other software your program needs

  3. Keeps track of everything installed

  4. Updates everything with one command

Why Package Managers Matter

Without package managers, installing software on Linux would be a nightmare. Imagine this:

  • You want to install a photo editor

  • The editor needs a graphics library

  • That library needs another library

  • You have to find and install each one manually

  • If versions don't match, nothing works!

Package managers solve all this automatically. They're one of Linux's killer features that makes system administration so much easier.


🏪 Meet the Package Manager Families

Linux has different "families" of distributions, and each family has its own package manager:

1. Debian/Ubuntu Family: APT

APT (Advanced Package Tool) is used by:

  • Ubuntu (the most popular for beginners)

  • Debian (the stable, reliable one)

  • Linux Mint (user-friendly Ubuntu derivative)

bash
# Check if you're using APT
which apt
# If it shows /usr/bin/apt, you're on an APT system

# Check your distribution
cat /etc/os-release | grep -i "ubuntu\|debian"

2. Red Hat Family: YUM and DNF

Used by enterprise and server distributions:

  • YUM (Yellowdog Updater Modified) - Older, still used

  • DNF (Dandified YUM) - Newer, faster replacement

  • Distributions: CentOS, RHEL, Fedora, Amazon Linux

bash
# Check if you're on Red Hat family
which yum || which dnf
cat /etc/redhat-release 2>/dev/null || cat /etc/system-release

3. SUSE Family: Zypper

Used by:

  • openSUSE

  • SUSE Linux Enterprise

bash
# Check for Zypper
which zypper

4. Arch Linux: Pacman

A different approach - rolling release, always up-to-date:

  • Arch Linux

  • Manjaro

bash
# Pacman command
pacman -S package_name

Why so many? Different distributions have different philosophies. Ubuntu focuses on user-friendliness, Red Hat on enterprise stability, Arch on cutting-edge software.

Good news: Once you learn one package manager, the concepts transfer to others. The commands are different, but the ideas are the same.


🔄 APT: The Debian/Ubuntu Package Manager

Understanding APT Architecture

APT has two main components:

  1. APT commands (aptapt-getapt-cache) - The tools you use

  2. DPKG - The lower-level tool that actually installs packages

Think of it like this:

  • APT = The friendly shop assistant who finds what you need

  • DPKG = The warehouse worker who actually unpacks and installs it

Basic APT Commands

bash
# Update package list (ALWAYS do this first!)
sudo apt update
# This doesn't update software, just refreshes what's available
# Like checking the app store for new app versions

# Upgrade installed packages
sudo apt upgrade
# Updates everything to latest versions
# Use regularly for security updates

# Install a package
sudo apt install nginx
# Installs nginx web server and all dependencies

# Remove a package
sudo apt remove nginx
# Removes nginx but keeps configuration files

# Remove package completely
sudo apt purge nginx
# Removes nginx AND configuration files

# Search for packages
apt search "web server"
# Finds packages related to web servers

# Show package information
apt show nginx
# Shows version, description, dependencies, size

# List installed packages
apt list --installed
# Shows everything installed

Advanced APT Usage

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

# Upgrade just one package
sudo apt install --only-upgrade nginx

# Download package without installing
sudo apt download nginx
# Gets the .deb file

# Clean up old packages
sudo apt autoremove
# Removes packages that were installed as dependencies but are no longer needed

# Clean download cache
sudo apt clean
# Removes downloaded .deb files (saves disk space)

Common APT Patterns for DevOps

bash
# Update and upgrade in one line (common in scripts)
sudo apt update && sudo apt upgrade -y
# -y = automatically answer "yes" to prompts

# Install multiple packages
sudo apt install nginx mysql-server php-fpm redis-server -y

# Check if package is installed
dpkg -l | grep nginx
# Or: apt list --installed | grep nginx

# Hold a package (prevent updates)
sudo apt-mark hold nginx
# Useful when you need a specific version

# Unhold a package
sudo apt-mark unhold nginx

# See what would be upgraded (dry run)
sudo apt upgrade --dry-run

🔴 YUM/DNF: The Red Hat Package Managers

YUM Basics (CentOS 7, RHEL 7)

bash
# Update package list
sudo yum check-update

# Install package
sudo yum install nginx

# Remove package
sudo yum remove nginx

# Update all packages
sudo yum update

# Search for packages
yum search "web server"

# Get package info
yum info nginx

# List installed packages
yum list installed

# Clean cache
sudo yum clean all

DNF Basics (CentOS 8+, RHEL 8+, Fedora)

DNF is the modern replacement for YUM. Commands are similar:

bash
# Update package list
sudo dnf check-update

# Install package
sudo dnf install nginx

# Remove package
sudo dnf remove nginx

# Update all
sudo dnf update

# Search
dnf search "web server"

# Clean cache
sudo dnf clean all

Key Differences Between APT and YUM/DNF

TaskAPT (Ubuntu)YUM/DNF (Red Hat)
Update package listapt updateyum check-update
Install packageapt installyum install
Remove packageapt removeyum remove
Searchapt searchyum search
Package files.deb.rpm
Config files/etc/apt//etc/yum.repos.d/

Memory trick: APT = "A Pretty Tool", YUM = "Yellowdog Updater Modified"


📚 Managing Repositories: Adding More Software Sources

What are Repositories?

Repositories are online software libraries where packages are stored. By default, your Linux system comes with official repositories. But sometimes you need to add more.

Think of repositories like different app stores:

  • Main repository = Official Apple App Store

  • PPA/EPEL = Third-party app stores with special apps

  • Your own repo = Your company's private app store

APT Repositories (Ubuntu/Debian)

Repository configuration files are in /etc/apt/sources.list and /etc/apt/sources.list.d/

bash
# View current repositories
cat /etc/apt/sources.list
ls /etc/apt/sources.list.d/

# Add a repository (PPA - Personal Package Archive)
sudo add-apt-repository ppa:nginx/stable
sudo apt update

# Add repository manually
echo "deb http://repo.example.com/ubuntu focal main" | sudo tee /etc/apt/sources.list.d/custom.list
sudo apt update

# Remove a repository
sudo add-apt-repository --remove ppa:nginx/stable
# Or delete the file: sudo rm /etc/apt/sources.list.d/custom.list

YUM/DNF Repositories (Red Hat)

Repository files are in /etc/yum.repos.d/ as .repo files

bash
# List repositories
yum repolist
# Or: dnf repolist

# View all repositories with details
yum repolist all

# Add EPEL repository (Extra Packages for Enterprise Linux)
# CentOS/RHEL 7:
sudo yum install epel-release

# CentOS/RHEL 8:
sudo dnf install epel-release

# Add repository manually
sudo vi /etc/yum.repos.d/custom.repo
# Add:
# [custom]
# name=Custom Repository
# baseurl=http://repo.example.com/
# enabled=1
# gpgcheck=1
# gpgkey=http://repo.example.com/RPM-GPG-KEY

# Enable/disable repository
sudo yum-config-manager --enable custom
sudo yum-config-manager --disable custom

Common Repositories You'll Need

  1. EPEL (Extra Packages for Enterprise Linux) - Must-have for CentOS/RHEL

  2. Docker Repository - For Docker installation

  3. Nginx Repository - Latest Nginx versions

  4. PHP Repository - Multiple PHP versions

  5. Your Company's Repo - Internal software


🔧 Building from Source: When Packages Aren't Enough

Why Build from Source?

Sometimes you need to:

  1. Get the absolute latest version (not in repositories yet)

  2. Customize compilation options

  3. Install software not available in repositories

  4. Debug or modify the software

Warning: Building from source is more complex and doesn't get automatic updates!

The Build Process

Most source code follows this pattern:

  1. Download the source code

  2. Extract it from archive

  3. Configure with your options

  4. Compile (make)

  5. Install (make install)

Example: Building Nginx from Source

bash
# Step 1: Install build tools
sudo apt update
sudo apt install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev -y
# For Red Hat: sudo yum groupinstall "Development Tools"

# Step 2: Download source
wget http://nginx.org/download/nginx-1.24.0.tar.gz
tar -xzvf nginx-1.24.0.tar.gz
cd nginx-1.24.0

# Step 3: Configure with custom options
./configure \
  --prefix=/usr/local/nginx \
  --with-http_ssl_module \
  --with-http_v2_module \
  --with-threads

# Step 4: Compile
make
# This can take several minutes

# Step 5: Install
sudo make install

# Step 6: Test
/usr/local/nginx/sbin/nginx -v

The Magic of Make

make reads a Makefile that contains build instructions. Common make commands:

bash
# Just compile (don't install)
make

# Install compiled software
sudo make install

# Clean up compiled files
make clean

# Remove installed files
sudo make uninstall

# Configure again
make distclean
./configure
make

Using Checkinstall (Better than make install)

Instead of make install, use checkinstall to create a package:

bash
# Install checkinstall
sudo apt install checkinstall

# Build and create .deb package
./configure
make
sudo checkinstall
# Creates a .deb file that can be managed by APT!

# Now you can remove it like any package
sudo dpkg -r nginx-custom

Why checkinstall is better: It keeps track of what files were installed, making cleanup easier.


🎯 Real-World DevOps Scenarios

Scenario 1: Setting Up a Web Server Stack

bash
# Ubuntu/Debian
sudo apt update
sudo apt install nginx mysql-server php-fpm php-mysql redis-server -y

# CentOS/RHEL 7
sudo yum install epel-release
sudo yum install nginx mariadb-server php-fpm php-mysql redis -y

# CentOS/RHEL 8
sudo dnf install epel-release
sudo dnf install nginx mariadb-server php-fpm php-mysql redis -y

# Start and enable services
sudo systemctl start nginx mysql php-fpm redis
sudo systemctl enable nginx mysql php-fpm redis

Scenario 2: Installing Docker

bash
# Ubuntu/Debian
# Remove old versions
sudo apt remove docker docker-engine docker.io containerd runc

# Add Docker repository
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

# Install Docker
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io -y

# Add user to docker group
sudo usermod -aG docker $USER

# Red Hat Family
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io -y
sudo systemctl start docker
sudo systemctl enable docker

Scenario 3: Managing Multiple PHP Versions

bash
# Ubuntu - Add PHP repository
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

# Install multiple PHP versions
sudo apt install php7.4 php7.4-fpm php7.4-mysql php7.4-curl
sudo apt install php8.1 php8.1-fpm php8.1-mysql php8.1-curl

# Switch default version
sudo update-alternatives --set php /usr/bin/php8.1

# Red Hat - Using Remi repository
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo dnf module reset php
sudo dnf module enable php:remi-8.1
sudo dnf install php php-fpm php-mysqlnd

Scenario 4: Creating an Installation Script

bash
#!/bin/bash
# save as: setup-server.sh

# Detect distribution
if [ -f /etc/os-release ]; then
    . /etc/os-release
    OS=$ID
else
    echo "Cannot detect OS"
    exit 1
fi

echo "Detected OS: $OS"

# Common packages
COMMON_PACKAGES="curl wget git vim htop net-tools"

case $OS in
    ubuntu|debian)
        echo "Updating APT..."
        sudo apt update
        sudo apt upgrade -y
        
        echo "Installing common packages..."
        sudo apt install $COMMON_PACKAGES -y
        
        echo "Installing web stack..."
        sudo apt install nginx mysql-server php-fpm -y
        ;;
        
    centos|rhel|fedora)
        echo "Installing EPEL repository..."
        sudo yum install epel-release -y
        
        echo "Installing common packages..."
        sudo yum install $COMMON_PACKAGES -y
        
        echo "Installing web stack..."
        sudo yum install nginx mariadb-server php-fpm -y
        ;;
        
    *)
        echo "Unsupported OS: $OS"
        exit 1
        ;;
esac

echo "Installation complete!"

🚨 Common Problems and Solutions

Problem 1: "Package not found"

bash
# Ubuntu/Debian
sudo apt update  # Refresh package list
apt search package_name  # Check exact name

# Red Hat
sudo yum clean all  # Clear cache
yum search package_name

Problem 2: "Broken dependencies"

bash
# Ubuntu/Debian
sudo apt --fix-broken install
sudo apt autoremove

# Red Hat
sudo yum clean all
sudo yum distro-sync

Problem 3: "Signature verification failed"

bash
# Update GPG keys
sudo apt-key update  # Ubuntu/Debian

# For Red Hat, check repository GPG key
sudo rpm --import https://repo.example.com/RPM-GPG-KEY

Problem 4: "Conflict with existing package"

bash
# Remove conflicting package first
sudo apt remove conflicting-package
# Or use --force option (carefully!)
sudo apt install --force-yes package_name

💡 Best Practices for Package Management

1. Always Update First

bash
# Before installing anything
sudo apt update  # or sudo yum check-update

2. Use Version Pinning for Production

bash
# Pin important packages to specific versions
echo "nginx hold" | sudo dpkg --set-selections  # Ubuntu
sudo yum versionlock nginx  # Red Hat

3. Keep a Package List

bash
# Export installed packages
apt list --installed > packages.txt  # Ubuntu
yum list installed > packages.txt    # Red Hat

# Reinstall on new server
xargs sudo apt install < packages.txt

4. Clean Regularly

bash
# Clean cache to save space
sudo apt clean          # Ubuntu
sudo yum clean all      # Red Hat
sudo dnf clean all      # Fedora/CentOS 8+

5. Test in Staging First

Always test package updates in staging environment before production!


📋 Quick Reference Cheat Sheet

TaskAPT (Ubuntu)YUM (Red Hat 7)DNF (Red Hat 8+)
Update package listsudo apt updatesudo yum check-updatesudo dnf check-update
Install packagesudo apt install pkgsudo yum install pkgsudo dnf install pkg
Remove packagesudo apt remove pkgsudo yum remove pkgsudo dnf remove pkg
Update allsudo apt upgradesudo yum updatesudo dnf upgrade
Searchapt search textyum search textdnf search text
Infoapt show pkgyum info pkgdnf info pkg
List installedapt list --installedyum list installeddnf list installed
Clean cachesudo apt cleansudo yum clean allsudo dnf clean all
Autoremovesudo apt autoremovesudo yum autoremovesudo dnf autoremove
Add repoadd-apt-repositoryAdd .repo file to /etc/yum.repos.d/Same as YUM

🚀 Practice Exercises

Exercise 1: Install and Configure a LAMP Stack

bash
# Ubuntu/Debian version
sudo apt update
sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql -y

# Test Apache
sudo systemctl start apache2
sudo systemctl enable apache2
curl http://localhost

# Test PHP
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
curl http://localhost/info.php

# Secure MySQL
sudo mysql_secure_installation

Exercise 2: Create a Custom Repository

bash
# Create a simple local repository
mkdir -p ~/myrepo/debian
cd ~/myrepo

# Download some .deb packages
apt download nginx curl wget

# Move to repository structure
mv *.deb debian/

# Create Packages.gz
cd debian
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz

# Test using it
echo "deb [trusted=yes] file:///home/user/myrepo ./" | sudo tee /etc/apt/sources.list.d/myrepo.list
sudo apt update
apt search myrepo

Exercise 3: Build and Package Software

bash
# Build htop from source
sudo apt install build-essential libncurses-dev -y
wget https://github.com/htop-dev/htop/archive/refs/tags/3.0.0.tar.gz
tar -xzf 3.0.0.tar.gz
cd htop-3.0.0

./autogen.sh
./configure
make

# Test it
./htop

# Create package with checkinstall
sudo apt install checkinstall
sudo checkinstall
# Follow prompts to create .deb package

# Now install the package
sudo dpkg -i htop_3.0.0-1_amd64.deb

🔗 Master Package Management with Hands-on Labs

Package management is a fundamental skill for every DevOps engineer. The best way to learn is through practical, hands-on experience.

👉 Practice package management across different Linux distributions at:
https://devops.trainwithsky.com/

Our interactive labs give you:

  • Real Ubuntu, CentOS, and Fedora systems to practice on

  • Common package management scenarios

  • Repository configuration exercises

  • Building from source tutorials

  • Production-like environments to test in


Frequently Asked Questions

Q: Should I use apt or apt-get?
A: Use apt for interactive use (better output, progress bars). Use apt-get in scripts (stable output format).

Q: How do I know which package manager my system uses?
A: Check for the commands: which apt or which yum or which dnf.

Q: What's the difference between remove and purge?
A: remove deletes the program but keeps config files. purge deletes everything including configs.

Q: How often should I update packages?
A: For servers: security updates immediately, other updates during maintenance windows. For workstations: weekly.

Q: Should I build from source or use packages?
A: Use packages whenever possible. Build from source only when you need specific features or latest versions not in repos.

Q: What if a package breaks my system?
A: You can often downgrade: sudo apt install package=old-version or use snapshot/backup before major updates.

Have package management questions or run into issues? Share your experience in the comments below! 💬

Comments

Popular posts from this blog

Introduction to Terraform – The Future of Infrastructure as Code

  Introduction to Terraform – The Future of Infrastructure as Code In today’s fast-paced DevOps world, managing infrastructure manually is outdated . This is where Terraform comes in—a powerful Infrastructure as Code (IaC) tool that allows you to define, provision, and manage cloud infrastructure efficiently . Whether you're working with AWS, Azure, Google Cloud, or on-premises servers , Terraform provides a declarative, automation-first approach to infrastructure deployment. Shape Your Future with AI & Infinite Knowledge...!! Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! In today’s digital-first world, agility and automation are no longer optional—they’re essential. Companies across the globe are rapidly shifting their operations to the cloud to keep up with the pace of innovatio...

📊 Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd

  Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd Monitoring and logging are essential for maintaining a healthy and well-performing Kubernetes cluster. In this guide, we’ll cover why monitoring is important, key monitoring tools like Prometheus and Grafana, and logging tools like Fluentd to help you gain visibility into your cluster’s performance and logs. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction In today’s fast-paced cloud-native environment, Kubernetes has emerged as the de-facto container orchestration platform. But deploying and managing applications in Kubernetes is just half the ba...

🔒 Kubernetes Security – RBAC, Network Policies, and Secrets Management

  Kubernetes Security – RBAC, Network Policies, and Secrets Management Security is a critical aspect of managing Kubernetes clusters. In this guide, we'll cover essential security mechanisms like Role-Based Access Control (RBAC) , Network Policies , and Secrets Management to help you secure your Kubernetes environment effectively. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction: Why Kubernetes Security Is Non-Negotiable As Kubernetes becomes the backbone of modern cloud-native infrastructure, security is no longer optional—it’s mission-critical . With multiple moving parts like containers, pods, services, nodes, and more, Kuberne...