Skip to main content
Linux Package Manager:

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:

commanddescription
sudo apt install <package-name>Installs the specified package and its dependencies.
sudo apt install ./file.debInstalls 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:

commanddescription
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 autoremoveRemoves 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:

commanddescription
sudo apt updateUpdates the local package index with the latest versions available in the repositories.
sudo apt upgradeInstalls the newest versions of all packages currently installed on the system.
sudo apt full-upgradeInstalls 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 installAttempts to fix broken dependencies.
apt list --upgradableLists 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:

CommandDescription
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 showholdLists held packages.

Package dependency & version tools #

CommandDescription
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 #

CommandDescription
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:

CommandDescription
sudo apt install -s <package-name>Simulates installation (no actual changes).
sudo apt remove -s <package-name>Simulates removal.

Fixing common issues #

CommandDescription
sudo dpkg --configure -aResolves interrupted package installations.
sudo apt-get checkChecks for broken dependencies.

Searching packages #

You can search for packages using keywords with the following commands:

commanddescription
apt search keywordSearches for packages with names or descriptions that match the keyword.
apt listLists packages based on a pattern or criteria.
apt show <package-name>Displays detailed information about a specific package.
apt list --installedLists all installed packages.

Clean up #

You can clean up your package cache and free up disk space with the following commands:

commanddescription
sudo apt cleanRemoves all package files from the local cache.
sudo apt autocleanRemoves only outdated package files from the cache.
sudo apt autoremoveRemoves unused packages that were automatically installed as dependencies.
sudo apt autoremove --purgeRemoves 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.

commanddescription
apt-cache search keywordSearches 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 statsOutputs 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:

CommandDescription
sudo add-apt-repository ppa:user/repoAdds a PPA repository.
sudo apt-add-repository --remove ppa:user/repoRemoves a PPA repository.
sudo apt edit-sourcesOpens /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
  1. <package-name>: The official name of the software package as recognized by the Advanced Package Tool (APT).
  2. version: The specific version of the package. This may include upstream version numbers and Debian or Ubuntu-specific revision identifiers.
  3. architecture: The target hardware architecture. Common values include amd64 (64-bit), i386 (32-bit), arm64 (64-bit ARM), or all (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:

commanddescription
sudo apt install vlcInstalls the latest available version of the vlc package for your architecture.
sudo apt show vlcDisplays 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:

Author

Jonas Jared Jacek • J15k

Jonas Jared Jacek (J15k)

Jonas works as project manager, web designer, and web developer since 2001. On top of that, he is a Linux system administrator with a broad interest in things related to programming, architecture, and design. See: https://www.j15k.com/

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.

All Topics

Random Quote

“Users spend most of their time on other sites. This means that users prefer your site to work the same way as all the other sites they already know.”

Jakob Nielsen Principal and Co-founder of the Nielsen Norman GroupJakob's Law of Internet User Experience, - IT quotes