π§° 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
apt
anddpkg
- How
snap
differs 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
apt
for most tasksβinstall, remove, update, and upgrade packages. - Use
dpkg
to manually install.deb
files. - Use
snap
to 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 :