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:
Downloads software from online repositories (like shopping in an app store)
Handles dependencies - automatically installs other software your program needs
Keeps track of everything installed
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)
# 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
# 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
# Check for Zypper which zypper
4. Arch Linux: Pacman
A different approach - rolling release, always up-to-date:
Arch Linux
Manjaro
# 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:
APT commands (
apt,apt-get,apt-cache) - The tools you useDPKG - 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
# 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
# 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
# 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)
# 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:
# 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
| Task | APT (Ubuntu) | YUM/DNF (Red Hat) |
|---|---|---|
| Update package list | apt update | yum check-update |
| Install package | apt install | yum install |
| Remove package | apt remove | yum remove |
| Search | apt search | yum 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/
# 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
# 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
EPEL (Extra Packages for Enterprise Linux) - Must-have for CentOS/RHEL
Docker Repository - For Docker installation
Nginx Repository - Latest Nginx versions
PHP Repository - Multiple PHP versions
Your Company's Repo - Internal software
🔧 Building from Source: When Packages Aren't Enough
Why Build from Source?
Sometimes you need to:
Get the absolute latest version (not in repositories yet)
Customize compilation options
Install software not available in repositories
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:
Download the source code
Extract it from archive
Configure with your options
Compile (make)
Install (make install)
Example: Building Nginx from Source
# 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:
# 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:
# 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
# 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
# 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
# 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
#!/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"
# 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"
# 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"
# 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"
# 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
# Before installing anything sudo apt update # or sudo yum check-update
2. Use Version Pinning for Production
# 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
# 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
# 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
| Task | APT (Ubuntu) | YUM (Red Hat 7) | DNF (Red Hat 8+) |
|---|---|---|---|
| Update package list | sudo apt update | sudo yum check-update | sudo dnf check-update |
| Install package | sudo apt install pkg | sudo yum install pkg | sudo dnf install pkg |
| Remove package | sudo apt remove pkg | sudo yum remove pkg | sudo dnf remove pkg |
| Update all | sudo apt upgrade | sudo yum update | sudo dnf upgrade |
| Search | apt search text | yum search text | dnf search text |
| Info | apt show pkg | yum info pkg | dnf info pkg |
| List installed | apt list --installed | yum list installed | dnf list installed |
| Clean cache | sudo apt clean | sudo yum clean all | sudo dnf clean all |
| Autoremove | sudo apt autoremove | sudo yum autoremove | sudo dnf autoremove |
| Add repo | add-apt-repository | Add .repo file to /etc/yum.repos.d/ | Same as YUM |
🚀 Practice Exercises
Exercise 1: Install and Configure a LAMP Stack
# 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
# 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
# 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
Post a Comment