Package Managers - Installing Software Like a Pro
Status: Active
Last Updated: 2026-01-30
Category: Basics - System Administration
Prerequisites: linux-fundamentals, bash-scripting
Time: 3-4 hours
Tags: package-manager, apt, dnf, pacman, brew, system-administration, software-installation
Summary
Master package managers across different Linux distributions and macOS. Learn to install, update, remove, and manage software dependencies like a system administrator. Say goodbye to downloading .exe files!
๐ฏ What You'll Learn
By the end of this article, you'll be able to:
- โ Understand what package managers do
- โ Use apt (Debian/Ubuntu)
- โ Use dnf (Fedora/RHEL)
- โ Use pacman (Arch)
- โ Use brew (macOS)
- โ Manage dependencies and updates
- โ Troubleshoot package issues
๐ What is a Package Manager?
The Old Way (Windows-style):
1. Google "download nginx"
2. Find official website
3. Download .tar.gz or .deb file
4. Figure out dependencies manually
5. Extract and compile (maybe?)
6. Hope it works
7. No automatic updates
8. Uninstalling? Good luck!
The Package Manager Way:
# One command installs everything:
sudo apt install nginx
# Updates all software:
sudo apt update && sudo apt upgrade
# Removes cleanly:
sudo apt remove nginx
Package Managers Handle:
- Dependency resolution
- Version management
- Security updates
- Clean uninstallation
- Repository management
- Binary distribution
๐ Package Manager Landscape
By Distribution
| Distribution | Package Manager | Package Format |
|---|---|---|
| Debian/Ubuntu | apt, apt-get | .deb |
| Fedora/RHEL | dnf, yum | .rpm |
| Arch/Manjaro | pacman | .pkg.tar.zst |
| openSUSE | zypper | .rpm |
| macOS | brew | Various |
| Alpine | apk | .apk |
This Guide Focuses On:
- apt (most popular - Debian/Ubuntu)
- dnf (enterprise - RHEL/Fedora)
- pacman (rolling release - Arch)
- brew (macOS)
๐ฆ APT - Debian/Ubuntu Package Manager
Understanding APT
APT = Advanced Package Tool
Two Commands:
apt- Modern, user-friendly interfaceapt-get- Original, script-friendly
Use apt for interactive work, apt-get for scripts.
Essential APT Commands
Update Package Lists (do this first!):
# Update available package information
sudo apt update
# See what can be upgraded
apt list --upgradable
Install Packages:
# Install single package
sudo apt install nginx
# Install multiple packages
sudo apt install nginx postgresql redis
# Install specific version
sudo apt install nginx=1.18.0-0ubuntu1
# Install without confirmation (scripts)
sudo apt install -y nginx
# Reinstall package
sudo apt install --reinstall nginx
Remove Packages:
# Remove package (keep config files)
sudo apt remove nginx
# Remove package and config files
sudo apt purge nginx
# Remove unused dependencies
sudo apt autoremove
# Remove and clean up
sudo apt purge nginx && sudo apt autoremove
Upgrade System:
# Upgrade all packages
sudo apt upgrade
# Upgrade with smart conflict resolution
sudo apt full-upgrade
# Upgrade distribution (Ubuntu 22.04 โ 24.04)
sudo do-release-upgrade
Search and Info:
# Search for package
apt search nginx
# Show package details
apt show nginx
# List installed packages
apt list --installed
# List files in package
dpkg -L nginx
# Find which package provides file
dpkg -S /usr/sbin/nginx
APT Sources and Repositories
Sources List Location: /etc/apt/sources.list
Example sources.list:
# Ubuntu main repositories
deb http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
Add Repository:
# Add PPA (Ubuntu)
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
# Add custom repository
echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list
# Add GPG key for repository
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Remove Repository:
# Remove PPA
sudo add-apt-repository --remove ppa:deadsnakes/ppa
# Remove repository file
sudo rm /etc/apt/sources.list.d/docker.list
APT Troubleshooting
Fix Broken Packages:
# Fix broken dependencies
sudo apt --fix-broken install
# Reconfigure broken packages
sudo dpkg --configure -a
# Force package removal
sudo dpkg --remove --force-remove-reinstreq package-name
Clear Cache:
# Clean downloaded package files
sudo apt clean
# Remove old package versions
sudo apt autoclean
Held Packages (prevent updates):
# Hold package at current version
sudo apt-mark hold nginx
# Unhold package
sudo apt-mark unhold nginx
# List held packages
apt-mark showhold
๐ฅ DNF - Fedora/RHEL Package Manager
Understanding DNF
DNF = Dandified YUM (replaced yum in Fedora 22+)
Enterprise Standard: Used in RHEL, Fedora, CentOS Stream, Rocky Linux, AlmaLinux
Essential DNF Commands
Update Package Database:
# Check for updates
sudo dnf check-update
# Update package database
sudo dnf makecache
Install Packages:
# Install package
sudo dnf install nginx
# Install multiple packages
sudo dnf install nginx postgresql redis
# Install without confirmation
sudo dnf install -y nginx
# Reinstall package
sudo dnf reinstall nginx
# Install local RPM file
sudo dnf install ./package.rpm
Remove Packages:
# Remove package
sudo dnf remove nginx
# Remove with dependencies
sudo dnf autoremove nginx
# Remove unused dependencies
sudo dnf autoremove
Upgrade System:
# Upgrade all packages
sudo dnf upgrade
# Alternative (same as upgrade)
sudo dnf update
# Upgrade to new release (Fedora)
sudo dnf system-upgrade download --releasever=39
sudo dnf system-upgrade reboot
Search and Info:
# Search for package
dnf search nginx
# Show package info
dnf info nginx
# List installed packages
dnf list installed
# List available packages
dnf list available
# Show package groups
dnf group list
# Install package group
sudo dnf group install "Development Tools"
History and Rollback:
# Show transaction history
sudo dnf history
# Undo last transaction
sudo dnf history undo last
# Redo transaction
sudo dnf history redo last
# Rollback to transaction ID
sudo dnf history rollback 50
DNF Repositories
List Repositories:
# List enabled repositories
dnf repolist
# List all repositories
dnf repolist --all
Add Repository:
# Add RPM Fusion (popular Fedora repo)
sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
# Add custom repository
sudo dnf config-manager --add-repo https://example.com/repo.repo
# Enable disabled repository
sudo dnf config-manager --set-enabled repository-name
EPEL (Extra Packages for Enterprise Linux):
# Install EPEL on RHEL/Rocky/Alma
sudo dnf install epel-release
DNF Performance
Speed Up DNF:
# Edit /etc/dnf/dnf.conf
sudo nano /etc/dnf/dnf.conf
# Add these lines:
max_parallel_downloads=10
fastestmirror=True
deltarpm=True
๐ช Pacman - Arch Linux Package Manager
Understanding Pacman
Pacman = Package Manager
Philosophy: Rolling release, always latest packages
Used In: Arch Linux, Manjaro, EndeavourOS
Essential Pacman Commands
Sync and Update:
# Sync package database
sudo pacman -Sy
# Update all packages
sudo pacman -Syu
# Force refresh and update
sudo pacman -Syyu
Install Packages:
# Install package
sudo pacman -S nginx
# Install multiple packages
sudo pacman -S nginx postgresql redis
# Install without confirmation
sudo pacman -S --noconfirm nginx
# Reinstall package
sudo pacman -S --force nginx
Remove Packages:
# Remove package
sudo pacman -R nginx
# Remove package and dependencies
sudo pacman -Rs nginx
# Remove package, dependencies, and config
sudo pacman -Rns nginx
# Remove orphaned packages
sudo pacman -Rns $(pacman -Qdtq)
Search and Info:
# Search remote packages
pacman -Ss nginx
# Search installed packages
pacman -Qs nginx
# Show package info
pacman -Si nginx
# Show installed package info
pacman -Qi nginx
# List files in package
pacman -Ql nginx
# Find package owning file
pacman -Qo /usr/bin/nginx
Query:
# List installed packages
pacman -Q
# List explicitly installed
pacman -Qe
# List dependencies
pacman -Qd
# List foreign packages (AUR)
pacman -Qm
AUR - Arch User Repository
AUR Helper (yay recommended):
# Install yay
sudo pacman -S --needed git base-devel
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
# Use yay (like pacman)
yay -S package-name
yay -Syu # Update all including AUR
yay -Ss search-term
Pacman Configuration
Config File: /etc/pacman.conf
# Enable parallel downloads
sudo nano /etc/pacman.conf
# Uncomment:
ParallelDownloads = 5
# Enable color output
Color
# Enable eye candy progress bar
ILoveCandy
Mirrors:
# Update mirror list
sudo reflector --latest 20 --sort rate --save /etc/pacman.d/mirrorlist
๐บ Homebrew - macOS (and Linux) Package Manager
Understanding Brew
Homebrew: The missing package manager for macOS
Also Works On: Linux (Homebrew on Linux)
Philosophy: User-space installation, no sudo for install
Installing Homebrew
macOS or Linux:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add to PATH (follow installer instructions)
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
Essential Brew Commands
Install Packages:
# Install package (formula)
brew install nginx
# Install GUI app (cask)
brew install --cask visual-studio-code
# Install multiple
brew install nginx postgresql redis
Remove Packages:
# Uninstall package
brew uninstall nginx
# Uninstall and remove all versions
brew uninstall --force nginx
# Remove unused dependencies
brew autoremove
Update:
# Update Homebrew itself
brew update
# Upgrade all packages
brew upgrade
# Upgrade specific package
brew upgrade nginx
# Prevent package from upgrading
brew pin nginx
brew unpin nginx
Search and Info:
# Search for package
brew search nginx
# Show package info
brew info nginx
# List installed packages
brew list
# List casks (GUI apps)
brew list --cask
# Show dependencies
brew deps nginx
Services (manage daemons):
# Start service
brew services start nginx
# Stop service
brew services stop nginx
# Restart service
brew services restart nginx
# List all services
brew services list
Maintenance:
# Check for issues
brew doctor
# Clean up old versions
brew cleanup
# Show what will be cleaned
brew cleanup -n
Homebrew Casks
GUI Applications:
# Install apps
brew install --cask firefox
brew install --cask docker
brew install --cask visual-studio-code
brew install --cask iterm2
# Search casks
brew search --casks browser
# Upgrade all casks
brew upgrade --cask
๐ง Advanced Package Management
Building from Source
Why Build from Source:
- Latest version not in repositories
- Custom compile options
- Learning purposes
- Specific optimizations
Typical Process:
# Download source
wget https://nginx.org/download/nginx-1.25.3.tar.gz
tar -xzf nginx-1.25.3.tar.gz
cd nginx-1.25.3
# Configure
./configure --prefix=/usr/local/nginx
# Compile
make
# Install
sudo make install
Managing Source-Built Software:
# Use a prefix to keep organized
./configure --prefix=/opt/myapp
# Or use /usr/local (standard)
./configure --prefix=/usr/local
# Better: Use a package manager alternative
# checkinstall (creates .deb or .rpm)
sudo apt install checkinstall
sudo checkinstall make install
Snap (Universal Packages)
Snap: Containerized packages that work across distros
# Install snap (Ubuntu usually has it)
sudo apt install snapd
# Install package
sudo snap install docker
# List installed
snap list
# Update
sudo snap refresh
# Remove
sudo snap remove docker
Pros: Latest versions, isolated, work everywhere
Cons: Larger size, slower startup, controversy
Flatpak (Universal Apps)
Flatpak: Another universal package format
# Install flatpak
sudo apt install flatpak
# Add Flathub repository
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
# Install app
flatpak install flathub org.gimp.GIMP
# Run app
flatpak run org.gimp.GIMP
# Update
flatpak update
AppImage (Portable Apps)
AppImage: Self-contained executable
# Download .AppImage file
wget https://example.com/app.AppImage
# Make executable
chmod +x app.AppImage
# Run
./app.AppImage
No installation needed!
๐ก Best Practices
Security
Always Update:
# Ubuntu/Debian
sudo apt update && sudo apt upgrade -y
# Fedora/RHEL
sudo dnf upgrade -y
# Arch
sudo pacman -Syu
# macOS
brew update && brew upgrade
Verify Package Sources:
# Check repository GPG keys
apt-key list # apt (deprecated, use keyring)
rpm -qa gpg-pubkey* # dnf
Only Add Trusted Repositories:
- Official distro repositories
- Well-known PPAs
- Verified third-party repos
System Hygiene
Remove Unused Packages:
# apt
sudo apt autoremove
sudo apt autoclean
# dnf
sudo dnf autoremove
# pacman
sudo pacman -Rns $(pacman -Qdtq)
# brew
brew autoremove
brew cleanup
Check Disk Usage:
# apt cache
du -sh /var/cache/apt/archives
# dnf cache
du -sh /var/cache/dnf
# brew cache
du -sh $(brew --cache)
Automation
Unattended Upgrades (Ubuntu/Debian):
# Install
sudo apt install unattended-upgrades
# Configure
sudo dpkg-reconfigure unattended-upgrades
# Edit config
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
DNF Automatic (Fedora/RHEL):
# Install
sudo dnf install dnf-automatic
# Configure
sudo nano /etc/dnf/automatic.conf
# Enable
sudo systemctl enable --now dnf-automatic.timer
๐จ Common Issues and Solutions
Issue 1: "Unable to locate package"
Cause: Package name wrong or repo not enabled
Solution:
# Update package lists
sudo apt update
# Search for correct name
apt search package-name
# Check if repo is added
apt policy package-name
Issue 2: "Broken packages"
Cause: Failed installation or interrupted upgrade
Solution:
# apt
sudo dpkg --configure -a
sudo apt --fix-broken install
# dnf
sudo dnf distro-sync
Issue 3: "Dependency hell"
Cause: Conflicting package versions
Solution:
# apt
sudo apt install aptitude
sudo aptitude install package-name # Better dependency resolution
# dnf
sudo dnf install --best --allowerasing package-name
Issue 4: "Repository not found"
Cause: Old repository URL or removed PPA
Solution:
# Remove broken repository
sudo rm /etc/apt/sources.list.d/broken-repo.list
sudo apt update
๐ Learning Path
Week 1: Package Manager Basics
Day 1: Understand your distribution's package manager
Day 2: Practice installing and removing packages
Day 3: Learn to search and get package info
Day 4: Update system safely
Day 5: Add a third-party repository
Month 1: Proficiency
- Comfortable installing any software
- Know how to troubleshoot package issues
- Understand dependencies
- Can add repositories safely
- Automate updates
Month 3: Mastery
- Build packages from source
- Create custom repositories
- Understand package formats (.deb, .rpm)
- Script package management
- Contribute to package maintenance
๐ What's Next?
After mastering package managers:
System Administration:
- kb/sysadmin/system-updates - Update strategies
- kb/security/package-security - Security updates
Containers (avoid dependency hell):
- kb/containers/docker-basics - Container basics
Infrastructure:
- kb/infrastructure/ansible-packages - Automate installs
๐ Resources
Documentation:
Package Search:
- packages.ubuntu.com
- pkgs.org - Multi-distro search
- formulae.brew.sh
๐ Change Log
2026-01-30
- Created comprehensive package manager guide
- Covered apt, dnf, pacman, and homebrew
- Included troubleshooting and best practices
- Added security and automation sections
- Provided learning path for package management mastery
๐ Congratulations! You've completed the basics section! You now have foundational knowledge to tackle containers, infrastructure, and beyond!
Next Step: Choose your path from day1-new-developer