When I first switched from CentOS to Ubuntu, it took me about a week to get comfortable with the package management system. Not because apt is hard — but because there are so many commands that look similar: apt, apt-get, apt-cache, dpkg… I never knew which one was the “right” one, or which was just an alias for another.
This article gets straight to the point. It’s not an A-Z beginner’s guide — it’s about helping you understand the big picture so you can use the right tool at the right time.
Comparing Package Management Tools on Ubuntu
Ubuntu doesn’t just have one — it has four main tools. Each exists for a reason:
1. dpkg — the Foundation of Everything
dpkg is the lowest layer, working directly with .deb files. It installs, removes, and queries installed packages. Its biggest limitation: no automatic dependency resolution. Try installing package A that requires B — dpkg throws an error and stops, unlike apt which goes out and fetches B automatically.
2. apt-get — the Old Wrapper, Rock-Solid Reliable
apt-get was created to solve exactly that limitation — automatically pulling dependencies from repositories. The reason it still survives in scripts to this day: its output format is extremely stable, and Canonical has committed to not changing it between versions. Dockerfiles from 2015 using apt-get still build fine today.
3. apt — the Modern Interface, More User-Friendly
Introduced in Ubuntu 16.04, apt was designed to replace apt-get for everyday use. It offers a progress bar, clearer color output, and combines many commands from apt-get + apt-cache in one place. Great for interactive use, but don’t rely on it in scripts since its output format isn’t guaranteed to stay stable.
4. snap — a Completely Different Approach
snap is Canonical’s own system. Each package bundles its entire dependency tree into a self-contained unit, runs in a sandbox, and updates automatically. Sounds great, but the tradeoff is size: the chromium snap weighs around 170MB, while installing via apt uses only ~80MB. On production servers I generally avoid snap for both reasons — it’s heavier and noticeably slower to start.
Pros and Cons of Each Tool
| Tool | Pros | Cons |
|---|---|---|
dpkg |
Install local .deb files directly, fast package info queries | No dependency resolution, cannot pull from repos |
apt-get |
Stable output, backward-compatible, ideal for scripts/CI | Output is harder to read interactively |
apt |
Progress bar, combines multiple commands, convenient for interactive use | Output format is not guaranteed to be stable |
snap |
Sandboxed, auto-updates, runs across many distros | Packages are ~2x larger, slower startup |
When I started out, I thought tutorials using apt-get meant apt was wrong. That’s not the case — both are correct, just for different contexts.
Choosing the Right Tool for Each Situation
Here’s the simple principle I follow:
- Everyday terminal use →
apt: Convenient, clean output, does everything you need. - Shell scripts, cron jobs, CI/CD →
apt-get: Stable output, no worries about Canonical changing the format. - Installing a manually downloaded
.debfile →dpkg -i: Then runapt-get install -fto fix any dependency issues. - Installing GUI apps, needing the latest version, or sandboxing →
snap: But avoid it on servers.
The Most Commonly Used apt Commands
Updating the Package List
Before installing anything, always run this first:
sudo apt update
Note: apt update only syncs the package list — it doesn’t upgrade any packages. To upgrade, use:
# Upgrade all installed packages
sudo apt upgrade
# Upgrade and handle adding/removing dependencies as needed
sudo apt full-upgrade
Installing and Removing Packages
# Install a single package
sudo apt install nginx
# Install multiple packages at once
sudo apt install git curl wget build-essential
# Remove package but keep config files
sudo apt remove nginx
# Remove package AND delete config — use when you want a clean reset
sudo apt purge nginx
# Remove leftover dependencies no longer needed
sudo apt autoremove
I tend to use purge instead of remove when uninstalling services like nginx or mysql. The reason: if I reinstall later, I don’t want old leftover config files to interfere.
Searching and Viewing Package Information
# Search for a package by name or description
apt search "web server"
# View detailed info about a package
apt show nginx
# Find which package provides a specific file/command
dpkg -S /usr/bin/curl
# List all installed packages
dpkg -l
# Check if a specific package is installed and its version
dpkg -l | grep nginx
Installing Local .deb Files
Most common when downloading .deb files from official sites — Google Chrome, VS Code, Slack…:
# Install a .deb file
sudo dpkg -i google-chrome-stable_current_amd64.deb
# If dependency errors occur, apt can fix them with this command
sudo apt-get install -f
Managing Repositories
# View the list of currently configured repositories
cat /etc/apt/sources.list
ls /etc/apt/sources.list.d/
# Add a PPA (Personal Package Archive)
sudo add-apt-repository ppa:ondrej/php
sudo apt update
# Remove a PPA
sudo add-apt-repository --remove ppa:ondrej/php
Other Useful Commands
# View package install/remove history
cat /var/log/apt/history.log
# Pin version, prevent automatic upgrades
sudo apt-mark hold nginx
# Remove the hold
sudo apt-mark unhold nginx
# List packages currently on hold
apt-mark showhold
# Clean the apt cache — typically frees up several hundred MB
sudo apt clean
Practical Tips from Real-World Experience
After running Ubuntu on both servers and dev machines, here are a few things I wish I’d known earlier:
- Always run
apt updatebeforeapt install— skipping this step often results in installing outdated packages or getting “package not found” errors even when the package exists in the repo. - Seeing the message “The following packages were automatically installed and are no longer required”? Run
sudo apt autoremoveto clean them up — nothing to worry about. - In automation scripts, add
-yandDEBIAN_FRONTEND=noninteractiveto suppress all interactive prompts:
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y nginx
- Want to know which packages are taking up the most disk space:
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -20
If you’re coming from CentOS/RHEL, switching to Ubuntu isn’t that hard. Just remember one rule: yum/dnf ≈ apt, and rpm ≈ dpkg. Same logic, different command names.

