Package Managers: Homebrew, apt, snap and flatpak Guide
In this tutorial, you'll learn package management across platforms including Homebrew on macOS, apt on Debian/Ubuntu, snap, flatpak, and choosing the right package manager for each use case.
Why Package Managers Matter
Installing software manually by downloading binaries from websites is error-prone, hard to update, and insecure. Package managers automate installation, updates, and removal. They verify package integrity, manage dependencies, and provide a single source of truth for what is installed on your system.
By the end of this guide, you will know how to use apt, Homebrew, snap, and flatpak, and understand when to use each.
What is a Package Manager?
A package manager is a tool that automates installing, upgrading, configuring, and removing software. It maintains a database of installed packages, resolves dependencies, and retrieves packages from repositories.
flowchart TD A[Package Manager] --> B[Repositories] B --> C[Official Repos] B --> D[PPAs / Third-Party] B --> E[User Repositories] A --> F[Dependency Resolution] A --> G[Install / Update / Remove] F --> H[Download Dependencies] F --> I[Version Conflicts]
apt: Debian and Ubuntu
apt (Advanced Package Tool) is the default package manager on Debian-based Linux distributions.
Basic Commands
# Update package index
sudo apt update
# Upgrade all packages
sudo apt upgrade
# Install a package
sudo apt install git curl wget
# Remove a package
sudo apt remove firefox
# Remove package and its config files
sudo apt purge firefox
# Search for packages
apt search python
# Show package info
apt show python3
# List installed packages
apt list --installed
Expected Output
$ apt search python
Sorting... Done
Full Text Search... Done
python3/jammy-updates,jammy-security 3.10.6-1~22.04.1 amd64
Interactive high-level object-oriented language (default python3 version)
$ apt show python3
Package: python3
Version: 3.10.6-1~22.04.1
Maintainer: Ubuntu Developers
Description: Interactive high-level object-oriented language
Adding PPAs
# Add a PPA
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.12
Homebrew: macOS and Linux
Homebrew is the de facto package manager for macOS. It also works on Linux.
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Basic Commands
# Install a package
brew install node python neovim
# Install a GUI application (cask)
brew install --cask visual-studio-code docker firefox
# Update Homebrew and package listings
brew update
# Upgrade all installed packages
brew upgrade
# Remove a package
brew uninstall python
# List installed packages
brew list
# Check for outdated packages
brew outdated
# Clean up old versions
brew cleanup
Expected Output
$ brew install node
==> Downloading https://ghcr.io/v2/homebrew/core/node/manifests/22.0.0
==> Installing dependencies: icu4c, c-ares, python@3.12
==> Installing node
==> Summary
🍺 /usr/local/Cellar/node/22.0.0: 2,456 files, 68MB
$ brew outdated
node (21.7.0 < 22.0.0)
python@3.12 (3.12.2 < 3.12.3)
Homebrew Services
# Start a service (e.g., PostgreSQL)
brew services start postgresql
# List services
brew services list
# Stop a service
brew services stop postgresql
Snap
Snap is a package management system developed by Canonical for Ubuntu. Snaps are sandboxed, auto-updating, and cross-distribution.
# Install snap (usually pre-installed on Ubuntu)
sudo apt install snapd
# Install a snap package
sudo snap install code --classic
sudo snap install postman
sudo snap install node --classic
# List installed snaps
snap list
# Update snaps
sudo snap refresh
# Revert to previous version
sudo snap revert code
# Remove a snap
sudo snap remove postman
Snap Channels and Confinement
| Channel | Purpose | Example |
|---|---|---|
stable |
Production-ready | sudo snap install Firefox |
candidate |
Release candidates | sudo snap install Firefox --channel=candidate |
beta |
Beta releases | sudo snap install Firefox --channel=beta |
edge |
Latest development | sudo snap install Firefox --channel=edge |
Flatpak
Flatpak is a cross-distribution package manager that provides sandboxed applications, primarily for desktop GUI software.
# Install flatpak
sudo apt install flatpak
# Add Flathub repository
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
# Install an application
flatpak install flathub org.gimp.GIMP
flatpak install flathub com.visualstudio.code
# List installed apps
flatpak list
# Update apps
flatpak update
# Run an app
flatpak run org.gimp.GIMP
# Remove an app
flatpak uninstall org.gimp.GIMP
Comparison Table
| Feature | apt | Homebrew | Snap | Flatpak |
|---|---|---|---|---|
| Platform | Linux only | macOS, Linux | Linux | Linux |
| Sandboxing | No | No | Yes | Yes |
| Automatic updates | No | Yes (brew upgrade) | Yes | Yes (via services) |
| GUI apps | Limited | Yes (casks) | Yes | Yes |
| CLI tools | Yes | Yes | Yes | Limited |
| Dependency handling | Shared | Shared | Bundled | Bundled |
| Repository model | Centralized (PPAs) | Centralized (taps) | Centralized (Snap Store) | Decentralized (remotes) |
Choosing the Right Package Manager
For Command-Line Tools
# Linux: Use apt first, then snap or Homebrew
sudo apt install jq ripgrep fzf
# macOS: Use Homebrew
brew install jq ripgrep fzf
For GUI Applications
# Linux: Prefer apt for system apps, Flatpak for sandboxed apps
sudo apt install firefox
flatpak install flathub org.gimp.GIMP
# macOS: Homebrew casks or App Store
brew install --cask visual-studio-code
For Development Tools
# Node.js: Consider nvm instead of package managers
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Python: Consider pyenv
brew install pyenv
# Docker: Package manager or direct install
brew install --cask docker
Common Errors
| Problem | Cause | Fix |
|---|---|---|
E: Unable to locate package |
Package not in Repository | Run sudo apt update first, or add a PPA |
brew: command not found |
Homebrew not in PATH | Run eval "$(/opt/homebrew/bin/brew shellenv)" |
| Snap commands fail | snapd not running | sudo systemctl enable --now snapd.socket |
| Flatpak permission denied | Missing permissions | Use flatpak override --user or Flatseal to manage permissions |
| Dependency conflicts with apt | Mixed sources | Use apt-mark to hold packages at specific versions |
Practice Questions
1. What command updates the package index on Debian/Ubuntu?
sudo apt update.
2. How do you install a GUI application with Homebrew?
brew install --cask <app-name>.
3. What is the difference between snap and flatpak in terms of sandboxing?
Both provide sandboxing. Snap uses AppArmor and is more restrictive; Flatpak uses Bubblewrap with configurable permissions.
4. How do you search for a package in apt?
apt search <keyword>.
5. What does brew cleanup do?
Removes old versions of installed formulae and casks, freeing disk space.
Challenge
Set up a development machine using only command-line package managers. Install Git, Node.js, Python, and Docker using the appropriate package manager for your OS. Create a script that installs your complete development toolchain in one command.
Real-World Task
On your current system, audit every installed package and remove those you no longer need. Use apt list --installed (Linux) or brew list (macOS) to list everything. Document the total number of packages and the disk space used. Create a setup script that installs only the packages you actually use for development.
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro