Table of Contents
Understanding APT on Debian/Ubuntu
APT (Advanced Package Tool) is the package management layer used by Debian, Ubuntu, and many derivatives (Linux Mint, Pop!\_OS, etc.). It works on top of .deb packages and a repository system, and is normally used via commands like apt, apt-get, and apt-cache.
This chapter focuses on:
- Basic APT workflows you’ll use daily
- The difference between
apt,apt-get, andapt-cache - How repositories and
sources.listrelate to APT - Handling common APT issues and errors
You should already know what package management is in general from the parent chapter.
The APT Command Family
On Debian-based systems, you’ll commonly see three related tools:
apt– modern, user-friendly front-end (recommended for everyday use)apt-get– older, script-friendly interface (still widely used)apt-cache– query package metadata (searching, showing info)
For interactive use as a human user:
- Prefer
aptfor most tasks. - Use
apt-getwhen following older docs or writing scripts where output stability matters.
Examples in this chapter will primarily use apt, and mention the older equivalents where useful.
Updating Package Information
Before installing or upgrading software, update APT’s local package index:
sudo apt updateWhat this does:
- Contacts all configured repositories
- Downloads up-to-date lists of available packages and versions
- Does not upgrade any installed packages by itself
Typical pattern:
sudo apt update
sudo apt upgradeOlder equivalents:
apt-get updateinstead ofapt updateapt-get upgradeinstead ofapt upgrade
Searching for Packages
To find packages by name or description:
apt search <keyword>Examples:
apt search firefox
apt search image editorThis may list many results. Each line usually looks like:
package-name/focal 1.2.3-1 amd64– package, version, architecture- A short description below
To get detailed information about a specific package:
apt show <package>Example:
apt show curlThis shows:
- Description
- Version
- Dependencies
- Repository origin
- Installed state (if installed)
Older equivalents:
apt-cache search <keyword>apt-cache show <package>
Installing Packages
To install a package:
sudo apt install <package>Examples:
sudo apt install curl
sudo apt install vlcYou can install multiple packages at once:
sudo apt install git build-essential cmakeAPT will:
- Download required
.debpackages from repositories - Resolve and install dependencies
- Prompt for confirmation (with an overview of what will be installed)
If you know a package is already up to date but not installed, apt will simply install it; you don’t need a separate “download” step.
Removing and Purging Packages
To remove a package but keep its configuration files:
sudo apt remove <package>Example:
sudo apt remove vlcTo remove a package and its configuration files:
sudo apt purge <package>Example:
sudo apt purge vlcPurging is useful if:
- You want a completely clean reinstall later
- You want to remove all traces of custom configuration
You can also use --purge with remove:
sudo apt remove --purge <package>Older equivalent:
apt-get remove,apt-get purge
Upgrading Installed Software
After sudo apt update, there are a few ways to upgrade:
`apt upgrade`
sudo apt upgrade- Upgrades installed packages to newer versions
- Does not remove installed packages
- Does not install new packages if that would be required in a way that changes dependencies too much
- Safe for routine updates
`apt full-upgrade` (or `dist-upgrade`)
sudo apt full-upgrade- More aggressive: can remove or install packages as needed to complete upgrades (e.g., kernel transitions)
- Needed sometimes during larger system updates
Older equivalence:
apt-get upgradeapt-get dist-upgrade(same behavior asapt full-upgrade)
For normal desktop use, apt upgrade regularly and apt full-upgrade occasionally (e.g., after a distribution release) is common.
Cleaning Up Downloaded Packages
APT caches downloaded .deb files in /var/cache/apt/archives. Over time, this can consume disk space.
Useful cleanup commands:
Remove unneeded package files
sudo apt autoclean- Removes obsolete package files from the cache (no longer downloadable)
Clear the entire package cache
sudo apt clean- Deletes all downloaded
.debfiles - You’ll need to re-download them if you reinstall or downgrade packages
Removing Automatically Installed Dependencies
When you install a package, APT may pull in dependencies that are no longer needed after you remove the original package.
To remove these “orphaned” dependencies:
sudo apt autoremove- Shows which packages will be removed
- Safe in normal circumstances, but skim the list before confirming
Viewing Installed Packages
To list all installed packages:
apt list --installedTo check if a specific package is installed:
apt list --installed | grep <package>or:
dpkg -l | grep <package>Basic pattern:
apt list --installed– quick overviewdpkg -l– more detailed info (Debian package database interface)
Managing Repositories (Basics)
Detailed repository configuration is handled elsewhere, but you should know how APT relates to repositories.
APT reads its repository configuration from:
/etc/apt/sources.list- Files in
/etc/apt/sources.list.d/(with.listextensions)
A typical entry in sources.list looks like:
deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverseYou normally:
- Don’t edit these files manually as a beginner
- Use your distribution’s GUI “Software & Updates” tool, or follow official instructions for adding a PPA or third-party repo
After any change to repositories, always run:
sudo apt updateso APT knows about the new or changed sources.
Installing from Local `.deb` Files
Sometimes software is distributed as a standalone .deb file (e.g., downloaded from a website).
To install a local .deb with APT dependency handling:
sudo apt install ./package-name.deb
Note the ./ – it tells APT to treat it as a local file, not a repo package.
Older method:
sudo dpkg -i package-name.deb
sudo apt -f install
Here, dpkg -i may leave unmet dependencies; apt -f install fixes them. Using apt install ./file.deb is simpler and preferred.
Lock Files and Parallel Package Managers
APT uses a lock file to prevent multiple package operations running at the same time. Common error:
:::text
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process XXXX (...)
Typical causes:
- A graphical update tool is running
- Another terminal is running
apt/apt-get/dpkg
Basic handling:
- Wait a bit – the other process might finish.
- Close any GUI “Software Updater” or “Software Center” windows.
- Don’t remove lock files manually unless you really know what you’re doing.
Check with:
ps aux | grep aptand wait for system package tasks to complete.
Common APT Errors and How to Approach Them
Some frequent issues and typical beginner-level responses:
“Unable to locate package”
Example:
:::text
E: Unable to locate package packagname
Possible causes:
- Typo in the package name
- Package is in a repository you don’t have enabled
- Package doesn’t exist for your distribution or version
What to try:
- Double-check spelling
- Run
sudo apt update - Search for similar names:
apt search <keyword>
“Failed to fetch” / Network errors
Example:
:::text
Failed to fetch http://...
Likely causes:
- No internet connection
- Temporary server issue
- Misconfigured repository
What to try:
- Check your internet connection
- Try again later
- If it’s a third-party repo, verify you followed its official instructions
Partial or broken installations
You might see messages about:
- “You have held broken packages”
- Install/upgrade failing halfway
Often, running:
sudo apt --fix-broken installcan resolve dependency issues by:
- Attempting to finish interrupted installs
- Installing missing dependencies
- Removing conflicting packages if necessary (it will ask first)
Practical Everyday Workflows
Here are some common “recipes” you’ll use with APT:
Install a program
sudo apt update
sudo apt install <program>Upgrade your system (routine)
sudo apt update
sudo apt upgradeRemove a program completely
sudo apt remove <program>
sudo apt autoremoveIf you also want to remove configs:
sudo apt purge <program>
sudo apt autoremoveFind and inspect a package
apt search <keyword>
apt show <package>When to Use `apt-get` Instead of `apt`
While apt is suitable for most tasks, you might still see apt-get:
- In older tutorials/scripts
- Where very stable, machine-oriented output is required
Useful apt-get subcommands parallel to apt:
apt-get update– same asapt updateapt-get install– same asapt installapt-get remove/purge– same semantics asaptapt-get upgrade/dist-upgrade– likeapt upgrade/full-upgrade
For a beginner working interactively, stick with apt unless you have a specific reason not to.
Summary
On Debian/Ubuntu and derivatives, APT is your main tool for:
- Keeping package lists current (
apt update) - Installing software (
apt install) - Removing software (
apt remove,apt purge) - Upgrading the system (
apt upgrade,apt full-upgrade) - Cleaning up (
apt autoremove,apt clean,apt autoclean) - Searching and inspecting packages (
apt search,apt show)
Comfort with these commands will cover the vast majority of software-management tasks you’ll do on Debian- and Ubuntu-based systems.