TL;DR
- APT is the package manager on Debian and Ubuntu — installs, updates and removes software.
- Always run
sudo apt updatebeforesudo apt install, otherwise you install from a stale index. apt(CLI for humans) andapt-get(CLI for scripts) share the same back-end — pick one and stay consistent.- Keep the system patched with
sudo apt upgrade; runsudo apt autoremoveafter upgrades to free disk.
What is the APT package manager?
The Advanced Package Tool (APT) is the package manager that ships with Debian and every Debian-derived distribution — Ubuntu, Linux Mint, Pop!_OS, Raspberry Pi OS and more. APT manages .deb packages by reading a list of configured repositories, resolving dependencies, downloading the right versions, and installing them in the correct order.
On a fresh server you’ll typically use four commands every week: apt update to refresh the package index, apt install to add software, apt upgrade to patch installed packages, and apt remove to take software away. Everything else — pinning, holds, reverse dependencies, source builds — is built on top of those four.
Prerequisites
- A Debian-family system (Debian 11/12, Ubuntu 22.04/24.04/26.04, Raspberry Pi OS, Mint, Pop!_OS).
sudoaccess — APT modifies system state.- Network connectivity to the configured repository mirrors (
/etc/apt/sources.listand/etc/apt/sources.list.d/).
How to use this guide
The sections below walk through the practical commands and options. After the main content you’ll find a Verification block (sanity-check it actually worked), a Troubleshooting block (common error messages and what to do), and Related reading for follow-on topics.
The Advanced Package Tool (APT) is a powerful command-line package manager used in Debian-based Linux distributions like Ubuntu.
It simplifies the process of installing, removing, updating, and managing software on your system. APT works by retrieving information from software repositories, which are online servers containing collections of packages.
Let’s learn how to use the APT Package Manager.
Introduction to APT package manager
APT simplifies software management by automatically handling package dependencies.
When you install a package, APT ensures that all required libraries and components are also installed.
Similarly, when you remove a package, it takes care of any unused dependencies.
How APT Package Manager Works
APT maintains a local database of available packages. This database is updated periodically by retrieving information from the repositories.
When you issue a command, the APT package manager consults this database to determine the actions needed to fulfill your request.

Common APT Commands
- Updating the Package List (
apt update)
This refreshes your local package database with the latest information from the repositories. It’s a good practice to run this command before installing or upgrading any packages.
sudo apt update- Upgrading Packages (
apt upgrade)
This command upgrades all installed packages to their latest versions available in the repositories. It is important to keep your system up-to-date to benefit from security patches and bug fixes.sh
sudo apt upgrade - Installing a Package (
apt install)
This command installs a specific package and its dependencies. Replacepackage_namewith the name of the package you want to install.
sudo apt install package_name- Removing a Package (
apt remove)
This command removes a specific package but keeps its configuration files. If you want to remove the configuration files as well, useapt purgeinstead.
sudo apt remove package_name- Searching for a Package (
apt search)
This command searches for packages matching a given keyword or pattern. It is useful when you don’t know the exact name of the package you are looking for.
apt search keyword- Listing Installed Packages (
apt list)
This command lists all installed packages on your system. You can use options to filter the output, such as--installedto show only installed packages or--upgradableto see packages with available updates.
apt list --installedAdditional APT Tips and Tricks
- Auto-remove Unneeded Packages (
apt autoremove):
This command removes packages that were installed as dependencies of other packages and are no longer needed.
sudo apt autoremoveThis is a handy way to save space. Here is an example of my output:
sudo apt autoremove
[sudo] password for rbailey:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED
libc-ares2 libjs-highlight.js libnode72 libwpe-1.0-1 libwpebackend-fdo-1.0-1 pigz python3-cliapp python3-markdown python3-pygments python3-ttystatus runc
0 to upgrade, 0 to newly install, 11 to remove and 6 not to upgrade.
After this operation, 66.8 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 280575 files and directories currently installed.)
Removing libnode72:amd64 (12.22.9~dfsg-1ubuntu3.5) ...
Removing libc-ares2:amd64 (1.18.1-1ubuntu0.22.04.3) ...
Removing libjs-highlight.js (9.18.5+dfsg1-1) ...
Removing libwpebackend-fdo-1.0-1:amd64 (1.14.2-0ubuntu0.22.04.1) ...
Removing libwpe-1.0-1:amd64 (1.14.0-0ubuntu0.22.04.1) ...
Removing pigz (2.6-1) ...
Removing python3-cliapp (1.20180812.1-4) ...
Removing python3-markdown (3.3.6-1) ...
Removing python3-pygments (2.11.2+dfsg-2) ...
Removing python3-ttystatus (0.38-4) ...
Removing runc (1.1.7-0ubuntu1~22.04.2) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.8) ...
- Fix Broken Dependencies (
apt install -f):
If you encounter dependency issues, this command attempts to resolve them by installing or removing packages as needed.
sudo apt install -f Here is an example output
sudo apt install -f snap
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed
snap
0 to upgrade, 1 to newly install, 0 to remove and 6 not to upgrade.
Need to get 377 kB of archives.
After this operation, 2,756 kB of additional disk space will be used.
Get:1 http://gb.archive.ubuntu.com/ubuntu jammy/universe amd64 snap amd64 2013-11-29-11 [377 kB]
Fetched 377 kB in 0s (1,973 kB/s)
Selecting previously unselected package snap.
(Reading database ... 279996 files and directories currently installed.)
Preparing to unpack .../snap_2013-11-29-11_amd64.deb ...
Unpacking snap (2013-11-29-11) ...
Setting up snap (2013-11-29-11) ...
Processing triggers for man-db (2.10.2-1) ...
- Hold a Package (
apt-mark hold package_name):
This prevents a package from being automatically upgraded.
- Unhold a Package (
apt-mark unhold package_name):
This allows a package to be upgraded again.
Important Considerations
- Always use
sudo: Most APT commands require administrative privileges. Usesudoto run them as the root user. - Keep Backups: Before performing major upgrades or changes, back up your important data to avoid potential data loss.
- Read Documentation: The APT documentation provides detailed information on all available commands and options.
Verification
Sanity-check the install / change actually worked:
- Run
apt --version— confirms APT is on the path. - Run
apt list --installed | wc -l— sanity-check the install count is reasonable. - Run
cat /etc/apt/sources.list— confirm your repository configuration is what you expect.
Troubleshooting
E: Could not get lock /var/lib/dpkg/lock — Another package operation is running (or crashed). Wait, or check with ps aux | grep -E 'apt|dpkg'. If nothing is running, the lock is stale — remove /var/lib/dpkg/lock-frontend and re-run sudo dpkg --configure -a.
E: Unable to locate package <name> — Either the package name is wrong (try apt search <name>) or the repository providing it isn’t enabled (e.g. universe on Ubuntu).
The following packages have unmet dependencies — Run sudo apt update first. If still broken, you may have a held package — apt-mark showhold. Avoid --force-yes on production.
Authoritative sources
For the canonical reference on APT semantics, see the Debian Apt wiki and apt(8).


Leave a Reply