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

Component | Role | Typical use

APT | Repository-aware package-management framework | Find packages, resolve dependencies, and coordinate changes

dpkg | Low-level Debian package utility | Install and track local .deb packages

apt-get | Command-line APT operation tool | Install, upgrade, remove, and maintain packages

apt-cache | Command-line metadata query tool | Search and inspect locally cached package information

Synaptic | GTK-based graphical package manager | Browse packages and apply APT changes through a GUI

Ubuntu Software Center | Ubuntu-oriented graphical software interface where available | Browse and install applications

aptitude | Interactive console and command-line APT client | Inspect and manage packages interactively or from scripts

KPackage | KDE-associated package-management front end in historical KDE environments | Provide a graphical package-management interface where supported

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 update

This 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-essential

APT 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 upgrade

upgrade 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-upgrade

The 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-name

Simulation 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-name

remove 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 autoremove

autoremove 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 autoclean

clean 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

Command | Effect | When to use | Important caution

update | Downloads current repository indexes | Before searching or applying updates | Does not upgrade installed packages

install | Installs requested packages and dependencies | Add software | Review additional packages and removals

upgrade | Upgrades installed packages without intentionally removing packages | Apply conservative routine updates | Some packages may remain back

full-upgrade or dist-upgrade | May install or remove packages to complete dependency changes | Handle larger dependency transitions | Simulate and inspect removals

remove | Removes package program files while normally retaining configuration | Uninstall while preserving configuration | Dependencies may remain

purge | Removes package files and system configuration | Completely remove package-managed configuration | Verify the package is not still needed

autoremove | Removes unneeded automatically installed dependencies | Clean up after removals | Review every proposed removal

clean | Removes all cached package archives | Reclaim cache disk space | Cached installers must be downloaded again

autoclean | Removes obsolete cached archives | Reclaim space conservatively | Does not remove all archives

-s operation | Simulates an operation | Preview important changes | It does not validate every runtime consequence

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-editor

search 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 curl

show 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 nginx

policy 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-name

depends 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 pkgnames

pkgnames 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

Command | Information returned | Example use case

search | Matching package names and descriptions | Find a package when only a keyword is known

show | Detailed package metadata | Review a package before installation

policy | Installed, candidate, and repository versions | Explain why a version is or is not selected

depends | Direct dependency relationships | Understand what a package requires

rdepends | Packages that rely on another package | Assess the impact of removing a library

pkgnames | Known package names | Inspect available names

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 autoremove later.

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=version

The 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-name

After 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

  1. Refresh metadata: Run sudo apt-get update and read repository errors.
  2. Search: Use apt-cache search keyword if you do not know the exact package name.
  3. Inspect: Use apt-cache show package, apt-cache policy package, and dependency queries.
  4. Simulate important changes: Run sudo apt-get -s ... when an operation may remove or replace packages.
  5. Apply the change: Install, upgrade, remove, or purge only after reviewing the summary.
  6. Verify: Check the installed version and status with apt-cache policy package and other package-status tools.
  7. Clean carefully: Consider autoremove, autoclean, or clean only 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

Action | Program files removed | Configuration retained | Unused dependencies affected

remove | Yes, for the selected package | Normally yes | Not necessarily removed

purge | Yes | Normally no for package-managed system configuration | Not necessarily removed

autoremove | Removes selected automatically installed packages | Depends on each package's removal state | Specifically targets dependencies no longer required

clean | Does not remove installed program files | Not applicable | Does not remove installed dependencies; clears cached archives

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.

  1. Run sudo apt-get update and read all errors.
  2. Try a broader search such as apt-cache search keyword.
  3. Use apt-cache policy package-name to see whether a candidate exists.
  4. 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 install

Use 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 update

Also 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-name

Disk 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 clean

Operational Cautions and Exam Notes

  • Remember the distinction: apt-get update refreshes package indexes; apt-get upgrade changes installed packages.
  • Know the hierarchy: APT is the higher-level dependency-aware framework; dpkg performs low-level Debian package installation and tracking.
  • Expect dependencies: Installing one package may install libraries, services, and supporting packages.
  • Understand full upgrades: full-upgrade or dist-upgrade may add or remove packages to satisfy dependency changes.
  • Distinguish removal commands: remove normally retains configuration, while purge removes package-managed system configuration.
  • Use metadata correctly: apt-cache is 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-name

This 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.