Lesson 13: Package Management
Goal: Learn to install, update, and manage software on Linux using different package managers.
Table of Contents
- apt — Debian/Ubuntu
- nala — Modern apt Frontend
- dpkg — Low-Level Package Tool
- snap — Universal Packages
- flatpak — Desktop Applications
- Homebrew — Cross-Platform
- AppImages — Portable Apps
- Comparing Package Formats
- Exercises
apt — Debian/Ubuntu
apt is the standard package manager for Debian-based distributions (Ubuntu, Mint, Pop!_OS).
Update package lists
# Always run this first to get the latest package info
sudo apt update
Upgrade installed packages
# Upgrade all packages
sudo apt upgrade
# Upgrade with automatic dependency resolution
sudo apt full-upgrade
# Combine update + upgrade
sudo apt update && sudo apt upgrade -y
Install packages
# Install a single package
sudo apt install nginx
# Install multiple packages
sudo apt install git curl wget htop
# Install without confirmation
sudo apt install -y docker.io
# Install a specific version
sudo apt install nginx=1.18.0-0ubuntu1
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
# Complete cleanup
sudo apt purge nginx && sudo apt autoremove
Search and info
# Search for packages
apt search "web server"
# Show package details
apt show nginx
# List installed packages
apt list --installed
# List upgradable packages
apt list --upgradable
# Check if a package is installed
apt list --installed | grep nginx
Cache management
# Show cache size
sudo du -sh /var/cache/apt/
# Clean downloaded packages
sudo apt clean
# Remove old versions from cache
sudo apt autoclean
nala — Modern apt Frontend
nala is a modern, user-friendly frontend for apt with better output and parallel downloads.
Install nala
sudo apt install nala
Usage (same as apt, just replace apt with nala)
# Update
sudo nala update
# Install
sudo nala install htop
# Upgrade
sudo nala upgrade
# Remove
sudo nala remove htop
# Search
nala search "text editor"
# Show package info
nala show vim
# History of all operations
nala history
Advantages of nala
- Cleaner, more readable output
- Parallel downloads (faster installs)
- Transaction history with undo
- Better dependency resolution display
Undo operations
# Show history
nala history
# Undo a specific operation
sudo nala history undo 5
Pick the fastest mirrors
sudo nala fetch
# Selects the 3 fastest mirrors for your location
dpkg — Low-Level Package Tool
dpkg manages individual .deb files directly.
# Install a .deb file
sudo dpkg -i package.deb
# If dependencies are missing, fix them
sudo apt install -f
# Remove a package
sudo dpkg -r package-name
# Purge (remove + config)
sudo dpkg -P package-name
# List all installed packages
dpkg -l
# Search installed packages
dpkg -l | grep nginx
# List files installed by a package
dpkg -L nginx
# Find which package owns a file
dpkg -S /usr/bin/curl
snap — Universal Packages
Snaps are containerized packages that work across distributions.
Install snapd
sudo apt install snapd
Basic usage
# Search for snaps
snap find "visual studio"
# Install a snap
sudo snap install code --classic
# List installed snaps
snap list
# Show snap info
snap info code
# Update all snaps
sudo snap refresh
# Remove a snap
sudo snap remove code
Classic vs strict confinement
# Strict: sandboxed, limited system access
sudo snap install firefox
# Classic: full system access (like apt)
sudo snap install code --classic
flatpak — Desktop Applications
Flatpak is another universal package format, popular for desktop applications.
Install flatpak
sudo apt install flatpak
# Add Flathub repository
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
Basic usage
# Search for apps
flatpak search firefox
# Install from Flathub
flatpak install flathub org.mozilla.firefox
# List installed apps
flatpak list
# Run an app
flatpak run org.mozilla.firefox
# Update all apps
flatpak update
# Remove an app
flatpak uninstall org.mozilla.firefox
# Clean up unused runtimes
flatpak uninstall --unused
Manage permissions — Flatseal
flatpak install flathub com.github.tchx84.Flatseal
Flatseal provides a GUI to manage Flatpak app permissions.
Homebrew — Cross-Platform
Homebrew (originally macOS) also works on Linux for installing developer tools.
Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Add to PATH (after install)
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.bashrc
source ~/.bashrc
Basic usage
# Install a package
brew install node
# Search
brew search python
# Update Homebrew itself
brew update
# Upgrade all packages
brew upgrade
# Info about a package
brew info node
# List installed packages
brew list
# Remove a package
brew uninstall node
# Cleanup old versions
brew cleanup
AppImages — Portable Apps
AppImages are single-file portable applications. No installation needed.
Using an AppImage
# 1. Download the AppImage
wget https://example.com/app.AppImage
# 2. Make it executable
chmod +x app.AppImage
# 3. Run it
./app.AppImage
Integrate with system
# Move to a standard location
mkdir -p ~/Applications
mv app.AppImage ~/Applications/
# Create a desktop entry for menu integration
cat > ~/.local/share/applications/myapp.desktop << EOF
[Desktop Entry]
Name=My App
Exec=$HOME/Applications/app.AppImage
Type=Application
Categories=Utility;
EOF
Comparing Package Formats
| Feature | apt/deb | snap | flatpak | AppImage | Homebrew |
|---|---|---|---|---|---|
| System integration | Deep | Moderate | Moderate | None | Moderate |
| Sandboxing | No | Yes | Yes | No | No |
| Auto-updates | Manual | Yes | Manual | No | Manual |
| Disk usage | Low | High | High | Low | Low |
| Speed | Fast | Slower | Moderate | Fast | Moderate |
| Best for | System packages | Server & desktop | Desktop apps | Portable apps | Dev tools |
Recommendation
- System packages (nginx, git, curl) →
apt - Desktop applications (Firefox, GIMP) →
flatpak - Developer tools (node, python) →
aptorbrew - Portable/testing → AppImage
Exercises
Exercise 1: apt basics
# 1. Update package lists
sudo apt update
# 2. Search for a package
apt search "terminal emulator"
# 3. Show info about a package
apt show htop
# 4. Check what can be upgraded
apt list --upgradable
# 5. Clean the package cache
sudo apt clean
Exercise 2: Install and remove
# 1. Install a small package
sudo apt install -y cowsay
# 2. Use it
cowsay "Hello Linux!"
# 3. Find where it was installed
which cowsay
dpkg -L cowsay
# 4. Remove it completely
sudo apt purge -y cowsay && sudo apt autoremove -y
Exercise 3: Try nala
# 1. Install nala
sudo apt install -y nala
# 2. Fetch fastest mirrors
sudo nala fetch
# 3. Install something with nala
sudo nala install -y tree
# 4. Check history
nala history
Key Takeaways
sudo apt update && sudo apt upgrade— keep your system up to dateapt install/apt remove— install/remove packagesnala— better apt experience with parallel downloadsdpkg -i file.deb— install individual .deb filessnap— sandboxed universal packagesflatpak— desktop apps from Flathub- AppImages — portable, no-install applications
- Always
apt updatebeforeapt install
Next Lesson: Lesson 14: Process Management →