Linux/Unix: Debian-Based Package Management β apt, dpkg, snap Explained with Examples
Introduction β Why Learn Debian-Based Package Tools?
If you’re using Ubuntu, Linux Mint, Kali, or any Debian-based distribution, then apt, dpkg, and snap are your go-to tools for installing, removing, and managing software. These package managers help you handle dependencies, updates, and even sandboxed applications from the terminal.
In this guide, youβll learn:
- How to install, remove, and update packages using
aptanddpkg - How
snapdiffers and when to use it - Real command examples and outputs for each tool
1. apt β Advanced Package Tool (User-Friendly)
What is apt?
apt is the front-end tool for Debian package management that automatically handles dependencies, repositories, and updates. It is interactive and scriptable.
Syntax:
sudo apt [command] [package]
Common apt Commands:
| Command | Description |
|---|---|
update | Refresh package list |
upgrade | Upgrade all installed packages |
install | Install a new package |
remove | Remove a package (keep config) |
purge | Remove a package and its config files |
search | Search for packages |
show | Show package details |
Examples:
Install a package:
sudo apt install vim
Update repositories:
sudo apt update
Upgrade all packages:
sudo apt upgrade
Remove a package:
sudo apt remove firefox
Output:
Reading package lists... Done
Building dependency tree... Done
The following packages will be REMOVED:
firefox
2. dpkg β Debian Package Manager (Low-Level)
What is dpkg?
dpkg is the low-level backend used by apt. It directly installs .deb files and does not handle dependencies automatically.
Syntax:
sudo dpkg [option] [package.deb]
Common dpkg Commands:
| Command | Description |
|---|---|
-i | Install a .deb package |
-r | Remove an installed package |
-P | Purge the package completely |
-l | List all installed packages |
-s | Show info about installed package |
-L | List files installed by a package |
Examples:
Install a local .deb package:
sudo dpkg -i google-chrome.deb
Output:
Unpacking google-chrome ...
Setting up google-chrome ...
Check if a package is installed:
dpkg -l | grep curl
If dependencies are missing:
sudo apt --fix-broken install
3. snap β Universal Linux Package Manager
What is snap?
snap packages are self-contained and sandboxed, designed to work across all Linux distros. Managed via the snap command, it installs apps with automatic updates and rollback.
Install Snap on Debian-based distros:
sudo apt install snapd
Syntax:
sudo snap [command] [package]
Common snap Commands:
| Command | Description |
|---|---|
install | Install a snap package |
remove | Remove a snap package |
list | List installed snaps |
info | Get details about a snap package |
refresh | Update installed snaps |
revert | Rollback to previous version |
Examples:
Install a snap:
sudo snap install code --classic
Output:
code 1.86.0 from Microsoftβ installed
List installed snaps:
snap list
Remove a snap:
sudo snap remove code
Tool Comparison: apt vs dpkg vs snap
| Feature | apt | dpkg | snap |
|---|---|---|---|
| Handles dependencies | |||
| Works offline | (needs repo) | (after initial download) | |
| GUI apps | (sandboxed) | ||
| Auto-updates | |||
| Rollback support |
Summary β Recap & Next Steps
Debian-based systems give you versatile package toolsβapt for daily management, dpkg for direct .deb installs, and snap for universal apps with rollback and confinement.
Key Takeaways:
- Use
aptfor most tasksβinstall, remove, update, and upgrade packages. - Use
dpkgto manually install.debfiles. - Use
snapto install modern sandboxed applications with auto-updates.
FAQs
What’s the difference between apt and dpkg?
apt resolves dependencies from repos. dpkg installs local .deb files without resolving dependencies.
How do I fix broken packages installed by dpkg?
Run:
sudo apt --fix-broken install
Are snap packages safe to use?
Yes. They’re confined (sandboxed) and receive automatic security updates.
Can I install GUI apps using snap?
Absolutely. Examples: snap install vlc, snap install code.
How do I completely remove a package and its config using apt?
Use:
sudo apt purge <package>
Share Now :
