APT cheat sheet
Summary
This APT cheat sheet provides a command reference for managing packages on Debian-based Linux systems. It covers installation, removal, upgrades, dependency management, repository control, troubleshooting, and usage of both apt and apt-cache commands.
Introduction #
The Advanced Package Tool (APT) is a command-line tool used for handling (installing, updating, removing, etc.) packages in Debian-based Linux distributions such as Ubuntu, Linux Mint, and Kali Linux.
For the package manager of Arch-based distributions, see the Pacman cheat sheet.
Package management #
Installing packages #
To install packages using APT:
| command | description |
|---|---|
sudo apt install <package-name> | Installs the specified package and its dependencies. |
sudo apt install ./file.deb | Installs a local .deb package file using APT. |
sudo apt install --no-install-recommends <package-name> | Installs only essential dependencies, skipping recommended packages. |
sudo apt install -y <package-name> | Automatically answers “yes” to prompts (useful for scripts). |
sudo apt reinstall <package-name> | Reinstalls a package without removing config files. |
Removing packages #
To remove installed packages:
| command | description |
|---|---|
sudo apt remove <package-name> | Removes the package but keeps the configuration files. |
sudo apt purge <package-name> | Removes the package and its configuration files. |
sudo apt autoremove | Removes automatically installed packages that are no longer needed. |
Updating and upgrading packages #
Use the following commands to update the package list and upgrade installed packages:
| command | description |
|---|---|
sudo apt update | Updates the local package index with the latest versions available in the repositories. |
sudo apt upgrade | Installs the newest versions of all packages currently installed on the system. |
sudo apt full-upgrade | Installs available upgrades, removing old packages if necessary to complete the upgrade. |
sudo apt dist-upgrade | (Synonym for full-upgrade) Upgrades packages, handling dependency changes smartly. |
sudo apt --fix-broken install | Attempts to fix broken dependencies. |
apt list --upgradable | Lists packages with available upgrades. |
Also see our article on how to update Ubuntu.
Holding/unholding packages (preventing upgrades) #
Sometimes you may want to freeze a package at its current version to avoid unwanted updates (e.g., for stability or compatibility reasons). Use these commands to manage held packages:
| Command | Description |
|---|---|
sudo apt-mark hold <package-name> | Prevents a package from being upgraded. |
sudo apt-mark unhold <package-name> | Allows upgrades for a held package. |
sudo apt-mark showhold | Lists held packages. |
Package dependency & version tools #
| Command | Description |
|---|---|
apt policy <package-name> | Shows version priorities and repository sources. |
apt depends -i <package-name> | Lists installed dependencies. |
apt-cache depends <package-name> | Lists all dependencies (including uninstalled). |
apt-cache rdepends <package-name> | Reverse dependencies (who needs this package). |
Downloading packages without installing #
| Command | Description |
|---|---|
apt download <package-name> | Downloads a .deb file without installing it. |
Simulating actions (-s or --dry-run) #
Before making actual changes to your system, you can test package operations in a safe, no-changes mode. These commands simulate installations or removals, showing what would happen without modifying your system:
| Command | Description |
|---|---|
sudo apt install -s <package-name> | Simulates installation (no actual changes). |
sudo apt remove -s <package-name> | Simulates removal. |
Fixing common issues #
| Command | Description |
|---|---|
sudo dpkg --configure -a | Resolves interrupted package installations. |
sudo apt-get check | Checks for broken dependencies. |
Searching packages #
You can search for packages using keywords with the following commands:
| command | description |
|---|---|
apt search keyword | Searches for packages with names or descriptions that match the keyword. |
apt list | Lists packages based on a pattern or criteria. |
apt show <package-name> | Displays detailed information about a specific package. |
apt list --installed | Lists all installed packages. |
Clean up #
You can clean up your package cache and free up disk space with the following commands:
| command | description |
|---|---|
sudo apt clean | Removes all package files from the local cache. |
sudo apt autoclean | Removes only outdated package files from the cache. |
sudo apt autoremove | Removes unused packages that were automatically installed as dependencies. |
sudo apt autoremove --purge | Removes unused packages and their config files. |
APT cache #
The apt-cache command #
apt-cache is a command-line tool that allows you to query the local APT package metadata cache. This cache contains information about available packages from all configured repositories. The data includes package descriptions, version numbers, dependencies, maintainers, and reverse dependencies. While many of its features have been integrated into the apt command, apt-cache is still valuable when you need more verbose or specific outputs.
The APT cache is updated whenever you run apt update, and the information retrieved by apt-cache reflects the current state of the local index, not the installed system.
| command | description |
|---|---|
apt-cache search keyword | Searches the package database for names and descriptions matching the keyword. Useful when you know part of the package name or function. |
apt-cache show <package-name> | Displays detailed information about the specified package, including version, size, dependencies, and a brief description. |
apt-cache depends <package-name> | Lists the package dependencies, showing which other packages must be installed for it to function properly. |
apt-cache rdepends <package-name> | Lists all packages that depend on the specified package. This helps you determine the impact of removing a package. |
apt-cache policy <package-name> | Displays the version and priority information for the specified package, including which repository it comes from. Useful for diagnosing repository conflicts. |
apt-cache stats | Outputs cache statistics, such as the number of packages and cache memory usage. Helpful for diagnosing issues or auditing system metadata. |
apt-cache showsrc <package-name> | Displays the source package information instead of the binary package. This is useful for developers or users who want to build software from source. |
While the apt command is preferred for everyday use due to its simpler interface, apt-cache provides more advanced functionality for troubleshooting, auditing, and development workflows.
Repository management #
APT repositories are servers hosting packages. You can add, remove, or manually edit repository sources with these commands:
| Command | Description |
|---|---|
sudo add-apt-repository ppa:user/repo | Adds a PPA repository. |
sudo apt-add-repository --remove ppa:user/repo | Removes a PPA repository. |
sudo apt edit-sources | Opens /etc/apt/sources.list for manual editing. |
Package names #
Debian package files use the .deb extension and follow a standard naming format that provides key details about the package:
<package-name>_<version>_<architecture>.deb
<package-name>: The official name of the software package as recognized by the Advanced Package Tool (APT).version: The specific version of the package. This may include upstream version numbers and Debian or Ubuntu-specific revision identifiers.architecture: The target hardware architecture. Common values includeamd64(64-bit),i386(32-bit),arm64(64-bit ARM), orall(architecture-independent).
Example:
vlc_3.0.11-0ubuntu1_amd64.deb
This file represents the VLC media player, version 3.0.11-0ubuntu1, built for the amd64 (64-bit x86) platform.
Using .deb file naming format in APT commands #
The <package-name> portion of a .deb file is used as the identifier in most APT commands. When you interact with the package manager, you do not need to specify the full file name or version—only the <package-name> is required. However, understanding the full format can help you interpret package metadata or perform advanced operations such as version-specific installations.
Here is how you can use the <package-name> from the .deb file in APT commands:
| command | description |
|---|---|
sudo apt install vlc | Installs the latest available version of the vlc package for your architecture. |
sudo apt show vlc | Displays detailed information about the vlc package, including its version, dependencies, and description. |
| … | Queries metadata about the vlc package from the local APT cache. |
By isolating the <package-name> from the .deb filename, you can interact with APT using concise and consistent commands. If you are manually downloading .deb files, you can also use:
sudo apt install ./vlc_3.0.11-0ubuntu1_amd64.deb
This installs the specified .deb file directly, and APT will handle any required dependencies automatically.
FAQ's #
Most common questions and brief, easy-to-understand answers on the topic:
What is APT in Linux?
APT stands for Advanced Package Tool and it is a package management system used by Debian and its derivatives like Ubuntu to install, update, and remove software.
What is the difference between apt and apt-get?
apt is a newer command-line interface that combines the most commonly used features of apt-get and apt-cache into a single command.
How do I completely remove a package including its configuration files?
Use the command sudo apt purge to remove a package and its configuration files.
How do I clean up unused packages and dependencies?
You can use sudo apt autoremove to remove packages that were automatically installed and are no longer needed.
How can I search for a package with APT?
You can search for packages using apt search keyword or apt-cache search keyword.
Further readings #
Sources and recommended, further resources on the topic:
License
APT cheat sheet by Jonas Jared Jacek is licensed under CC BY-SA 4.0.
This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/apt-cheat-sheet">APT cheat sheet</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>For more information see the Ditig legal page.