VMware ESXi and vSphere Cluster Management
Advanced Packaging Tool (APT) in Linux: apt-get, apt-cache, and Package Management
Learn how APT manages Debian packages, repositories, dependencies, updates, installations, removals, versions, and package searches with apt-get and apt-cache.
Advanced Packaging Tool (APT) is the repository-aware package-management framework used by Debian, Ubuntu, and related Linux distributions. It helps you find, install, update, upgrade, inspect, and remove software packages.
This lesson focuses on the traditional command-line tools apt-get and apt-cache. You will also see how APT relates to dpkg, repositories, package indexes, dependencies, graphical front ends, and safe maintenance workflows.
What APT Is and What It Manages
APT stands for Advanced Packaging Tool. It is used by Debian-family systems to work with software distributed as Debian binary packages. A Debian package normally has a .deb filename extension.
APT is a higher-level interface around dpkg. The lower-level dpkg utility installs and tracks local .deb files, records package status, and manages files belonging to packages. APT adds repository access, package-index searches, version selection, and dependency resolution.
In a typical operation, APT obtains package metadata and package archives from configured repositories, calculates a suitable transaction, and then invokes dpkg to perform the low-level installation or removal. A package transaction is the complete set of changes APT proposes for one operation.
APT components and responsibilities
Front-end availability depends on the distribution release and desktop environment. All of these interfaces may ultimately use APT and the Debian package system, but their screens and command syntax differ.
Repositories, Sources, and Package Indexes
A repository is a software source that provides packages and package metadata to APT. A repository may contain packages for a particular distribution release, architecture, and repository component.
APT learns which repositories to use from source definitions. The main configuration file is /etc/apt/sources.list. Additional definitions are commonly stored in files below /etc/apt/sources.list.d/.
/etc/apt/sources.list
/etc/apt/sources.list.d/These files tell APT where to obtain package indexes and archives. Do not mix repositories intended for unrelated distribution releases or incompatible vendors without understanding the consequences. Inconsistent sources are a common cause of dependency conflicts.
A package index is locally downloaded metadata about repository packages. It can include package names, versions, descriptions, dependencies, architecture information, and repository origin. APT uses this metadata when searching, selecting versions, and calculating dependencies.
Package indexes are not the same as installed software. Refreshing them updates APT's knowledge of what repositories offer; it does not install or upgrade packages.
Dependencies and Dependency Resolution
A dependency is a package or capability required by another package. For example, a command-line application may depend on shared libraries, certificates, helper utilities, or a service.
When you request a package, APT examines its dependency relationships and normally installs the required packages automatically. It can also determine that completing a change requires upgrading, replacing, or removing other packages.
Dependency resolution is why installing one small application can result in several additional packages being downloaded. Those packages may be direct dependencies or dependencies of other dependencies.
APT also evaluates conflicts and package transitions. A full upgrade may need to add replacement packages, remove obsolete packages, or upgrade several related packages together. Always review the proposed transaction, especially when removals are listed.
Refreshing Package Index Data with apt-get update
Run apt-get update to contact enabled repositories and download current package indexes.
sudo apt-get updateThis command updates the local package database. It does not upgrade installed packages, install new software, or remove anything by itself. Run it before searching for newly published packages or applying updates.
Read the command output. Repository errors, expired metadata, unreachable sources, authentication failures, or incorrect distribution names can leave your local information incomplete.
The apt-get Command
apt-get is a command-line APT program for automated package installation, upgrades, removal, and maintenance. System-wide changes normally require root privileges, so commands commonly begin with sudo.
Installing one or more packages
sudo apt-get install curl
sudo apt-get install git make build-essentialAPT calculates dependencies, displays the packages it will install or change, shows download and disk-space information, and usually asks for confirmation. The first command installs one package; the second installs several related tools in one operation.
Review the additional packages and proposed changes before confirming. If the package name is wrong or no candidate version exists, APT will report that it cannot locate the package.
Upgrading installed packages
sudo apt-get update
sudo apt-get upgradeupgrade installs newer versions of installed packages when the operation can proceed without intentionally removing packages. It may leave some packages unchanged if their dependency changes require a more disruptive transaction.
full-upgrade, also known as dist-upgrade in APT terminology, can install or remove packages to satisfy changed dependencies.
sudo apt-get full-upgrade
sudo apt-get dist-upgradeThe name dist-upgrade does not by itself mean that the operating system release will change. It describes a more flexible package upgrade operation. A distribution release upgrade is a separate, distribution-specific process.
Simulating an operation
Use simulation mode before potentially disruptive changes. The -s option calculates and displays the transaction without changing the system.
sudo apt-get -s install package-name
sudo apt-get -s full-upgrade
sudo apt-get -s remove package-nameSimulation is especially useful when a full upgrade proposes removals or when you are unsure about the effect of a package operation.
Removing and purging packages
sudo apt-get remove package-name
sudo apt-get purge package-nameremove uninstalls a package but normally retains its system-level configuration files. purge removes the package and its system-level configuration files. Configuration in a user's home directory may remain and is not automatically equivalent to package-managed system configuration.
Removing unused dependencies
sudo apt-get autoremoveautoremove removes packages that APT marked as automatically installed dependencies and that are no longer needed by any manually installed package. Inspect the proposed list carefully: a package that looks unused to APT may still be needed for a workflow you installed outside the package manager.
Cleaning downloaded package archives
sudo apt-get clean
sudo apt-get autocleanclean removes all downloaded package archive files from APT's local cache. autoclean removes only obsolete archives that can no longer be downloaded from configured repositories. These commands remove cached installers, not installed program files.
Common apt-get operations
The apt-cache Command
apt-cache examines APT's locally available package metadata. It is primarily informational: its normal queries do not install or remove packages.
Searching by keyword
apt-cache search text-editorsearch checks package names and descriptions for matching text. Use a broad keyword when you do not know the exact package name, then inspect promising results with show.
Viewing package details
apt-cache show curlshow displays metadata such as the package description, version, architecture, dependencies, download size, installed size, and repository-related information.
Checking versions with policy
apt-cache policy nginxpolicy helps compare the installed version, the candidate version, and versions available from configured repositories. The candidate version is the version APT currently selects for installation or upgrade based on enabled sources and preferences.
Inspecting dependency relationships
apt-cache depends package-name
apt-cache rdepends library-namedepends displays direct dependencies of a package. rdepends displays reverse dependencies: packages that depend on the named package. Reverse-dependency output can be extensive, so use it as an investigation tool rather than assuming every listed relationship means the package can be safely removed.
Listing package names
apt-cache pkgnamespkgnames lists package names known to the local package cache. It is useful for basic name-oriented inspection but does not provide the descriptions and filtering behavior of search.
Useful apt-cache queries
Package Status and Version Concepts
APT and dpkg track more than whether a package exists. These concepts help explain command output:
- Installed: The package is currently present on the system.
- Available: A package version is known from one or more configured repositories, whether or not it is installed.
- Candidate: The version APT currently prefers for installation or upgrade.
- Upgradable: An installed package has a newer suitable candidate version.
- Manually installed: APT treats the package as something the user explicitly requested and will not normally remove it as an unused dependency.
- Automatically installed: APT installed the package to satisfy another package's dependency. It may become eligible for
autoremovelater.
APT selects versions using repository availability and preferences such as repository priority. A higher priority does not always mean a package is installed immediately; the candidate must also be compatible with the requested operation.
Requesting a specific version
apt-cache policy package-name
sudo apt-get install package-name=versionThe exact version must be available to APT, and the version string must match the repository metadata. Requesting an older or non-default version can create dependency problems, so inspect the policy output and simulate the operation first.
Holding a package
A package hold prevents a package from being automatically upgraded. Holds can be useful when a known compatibility issue requires a package to remain at its current version, but they can also hide security or dependency updates.
sudo apt-mark hold package-name
sudo apt-mark unhold package-nameAfter setting a hold, use apt-cache policy package-name and your distribution's package-status tools to investigate unexpected upgrade behavior. Remove the hold when it is no longer needed.
A Safe APT Workflow
- Refresh metadata: Run
sudo apt-get updateand read repository errors. - Search: Use
apt-cache search keywordif you do not know the exact package name. - Inspect: Use
apt-cache show package,apt-cache policy package, and dependency queries. - Simulate important changes: Run
sudo apt-get -s ...when an operation may remove or replace packages. - Apply the change: Install, upgrade, remove, or purge only after reviewing the summary.
- Verify: Check the installed version and status with
apt-cache policy packageand other package-status tools. - Clean carefully: Consider
autoremove,autoclean, orcleanonly after reviewing their effects.
System-wide package changes, upgrades, removals, and source-file edits normally require root privileges, commonly obtained through sudo. Do not interrupt an active package transaction unless you have a specific recovery procedure. On important systems, create a backup or snapshot before large upgrades or removals.
APT Front Ends
APT is available through direct command-line tools as well as graphical and console-oriented front ends.
- Synaptic Package Manager: A GTK-based graphical interface for searching, inspecting, selecting, and applying APT package changes.
- Ubuntu Software Center: A graphical Ubuntu-oriented interface for browsing and installing software where provided by the release.
- aptitude: A console-oriented APT client with both interactive and command-line modes.
- KPackage: A KDE-associated package-management front end found in some historical KDE environments.
These applications may not be installed by default. Names, features, and availability vary by distribution release and desktop environment. A graphical interface does not remove the need to review dependencies, removals, repository sources, and version choices.
Package Removal Choices
Troubleshooting APT Problems
A package cannot be found
Possible causes include stale metadata, an incorrect package name, a disabled repository component, or a package unavailable for the current release or architecture.
- Run
sudo apt-get updateand read all errors. - Try a broader search such as
apt-cache search keyword. - Use
apt-cache policy package-nameto see whether a candidate exists. - Review enabled source definitions before adding or changing repositories.
APT reports unmet dependencies or broken packages
An interrupted transaction, conflicting versions, or incompatible repositories can produce broken dependencies. Review the exact packages named by APT. After refreshing metadata, a dependency repair may be appropriate:
sudo apt-get -f installUse this deliberately and inspect the proposed changes. Avoid force-removing packages before understanding their dependency relationships. Correct or disable incompatible source entries and retry.
An expected upgrade is not offered
The installed version may already be the candidate, a hold may be active, repository priorities may select another version, or the package index may be outdated. Check:
apt-cache policy package-name
sudo apt-get updateAlso inspect package holds with the package-selection tools available on your system and verify that the intended repositories are enabled.
An upgrade proposes removal of important packages
This may be a legitimate dependency transition, repository mixing, or an attempted major release change. Do not confirm immediately. Simulate the operation, inspect candidate versions and dependencies, and restore consistent repository definitions before proceeding if the proposal is unexpected.
sudo apt-get -s full-upgrade
apt-cache policy package-name
apt-cache depends package-nameDisk space is low
Downloaded package archives may remain in the local cache, and unused dependencies may still be installed. Review the proposed removals, then use the appropriate cleanup command:
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get cleanOperational Cautions and Exam Notes
- Remember the distinction:
apt-get updaterefreshes package indexes;apt-get upgradechanges installed packages. - Know the hierarchy: APT is the higher-level dependency-aware framework;
dpkgperforms low-level Debian package installation and tracking. - Expect dependencies: Installing one package may install libraries, services, and supporting packages.
- Understand full upgrades:
full-upgradeordist-upgrademay add or remove packages to satisfy dependency changes. - Distinguish removal commands:
removenormally retains configuration, whilepurgeremoves package-managed system configuration. - Use metadata correctly:
apt-cacheis primarily informational and uses locally cached indexes. - Read transaction summaries: Pay attention to packages to be removed, newly installed packages, held packages, and disk-space changes.
- Keep sources consistent: Mixing distribution releases or incompatible third-party repositories can make dependency resolution unsafe.
Summary
APT manages Debian-family software by combining configured repositories, locally cached package indexes, dependency resolution, and the low-level dpkg tool. Use apt-cache to search and inspect package metadata, then use apt-get to apply carefully reviewed changes.
sudo apt-get update
apt-cache search keyword
apt-cache show package-name
apt-cache policy package-name
sudo apt-get -s install package-name
sudo apt-get install package-nameThis sequence refreshes package knowledge, investigates a package, previews the installation, and then applies it. The same review-first approach is appropriate for upgrades, removals, purges, and cleanup.