#

Packages

Subscribe
Packages October 29, 2026·9 min read

How to Use the apt Command in Linux

On Debian and Ubuntu, update refreshes the package lists, install adds software, and upgrade applies regular updates. Broader operations can add or remove packages, so read the proposed changes before confirming and check the result afterwards.

What is apt, and which command should you use?

APT command reference

APT, the Advanced Package Tool, manages Debian packages and their dependencies. The apt command is the interactive interface for finding, installing, upgrading, and removing software.

In the table, NAME is the package name you supply.

TaskCommandEffect
Find softwareapt search NAMESearch indexed package information
Read package detailsapt show NAMEShow description and dependencies
List installed packagesapt list --installedShow installed packages
Find available updatesapt list --upgradableList packages with available upgrades
Compare versionsapt policy NAMEShow installed and candidate versions
Refresh package metadatasudo apt updateDownload repository information
Install a packagesudo apt install NAMEInstall a named package and dependencies
Apply regular upgradessudo apt upgradeUpgrade without removing installed packages
Permit broader upgradessudo apt full-upgradeMay add and remove packages
Remove a packagesudo apt remove NAMERemove named software
Remove packaged settingssudo apt purge NAMERemove package and packaged configuration
Clean up dependenciessudo apt autoremovePropose unused automatic dependencies for removal
APT package tasks

Read-only commands work without elevated privileges. Commands that change packages need root, for example through sudo.

Other Linux families, including Fedora and Arch, use different package managers.

Find a package and check its version before installing it

APT package lookup

Get the package name right first. A project's public name, its Debian package name and the version in your repositories can all differ.

To look for curl, search the index and read its description:

apt search curl
apt show curl

Search runs against the metadata already on your machine. show gives the description, package size and dependencies.

To see the installed and candidate versions:

apt policy curl

For the full lists of installed packages and pending upgrades:

apt list --installed
apt list --upgradable

Your OS release, your enabled repositories and the state of your package index decide what you can install. A tutorial can name versions your machine can't install.

Install, reinstall, or select a package version

APT install commands

To install a package from your repositories, use its name:

sudo apt install curl

APT resolves the dependencies the install needs and asks you to confirm the changes. Installing a package you already have upgrades it if a newer candidate is selected.

Reinstall package-managed files

If a package's files need to be installed again, use the reinstall option:

sudo apt install --reinstall curl

Reinstalling restores the package's own files. It won't fix your data, your service settings or other problems with the application.

Request an available version

If your package policy offers a specific version, add it to the package name. Replace VERSION with the exact version listed by apt policy:

sudo apt install curl=VERSION

A local .deb file raises different source and dependency questions than a repository package.

apt update vs upgrade vs full-upgrade: what each one changes

APT upgrade comparison

apt update refreshes package information. apt upgrade installs available updates. apt full-upgrade allows dependency resolution that can remove installed packages.

OperationRefreshes metadataInstalls upgradesMay add dependenciesMay remove installed packages
sudo apt updateYesNoNoNo
sudo apt upgradeNoYesYesNo
sudo apt full-upgradeNoYesYesYes
sudo apt-get upgradeNoYesNoNo
APT dependency changes

A regular maintenance run looks like this:

sudo apt update
sudo apt upgrade

You can chain the steps with the shell's conditional operator:

sudo apt update && sudo apt upgrade

The second command runs only if the first exits successfully. Even then, repository-fetch warnings can mean APT kept older package lists for some sources.

A Debian user on r/debian asked in May 2025, “Is it correct to perform these three commands after each other every time you do a upgrade of the system?” You do not need to add full-upgrade to a routine upgrade.

Details are in the Debian apt manual.

Updating packages is different from upgrading to another OS release. full-upgrade alone does not change the configured distribution release.

apt remove vs purge vs autoremove: which one deletes what

APT removal commands
CommandRemoval scopeConfiguration consequenceWhen it fits
sudo apt remove NAMENamed packageSome system configuration can remainYou may want the settings later
sudo apt purge NAMENamed package and packaged configurationRemoves packaged configurationYou no longer need those settings
sudo apt autoremoveNo-longer-required automatic dependenciesDepends on packages selected for removalYou have evaluated the proposed list

To remove curl and keep the configuration APT preserves:

sudo apt remove curl

To purge its packaged configuration too:

sudo apt purge curl

Purging does not erase application data that users created in their home directories.

Automatic dependency removal

autoremove relies on APT's dependency records. Once the packages that required an automatically installed dependency are gone, that dependency becomes a candidate for removal. The automatic mark only records how APT tracks a package.

Check the marks with apt-mark showauto and apt-mark showmanual. If you rely on a package that is marked automatic, mark it manual by putting its exact name in place of PACKAGE:

sudo apt-mark manual PACKAGE

This only changes how APT tracks the package.

Preview APT changes before confirming

APT transaction preview

The transaction preview lists the package additions, removals and configuration steps.

To simulate an install or a dependency cleanup, use apt-get:

apt-get -s install curl
apt-get -s autoremove

In the output, Inst means a package is being installed or unpacked, Remv means removal, and Conf means configuration. The Debian apt-get manual covers these markers and the simulation option.

APT removal preview

A simulation does not lock package state. The real transaction can differ if repository information or installed packages change before the real run. Running the simulation without suitable privileges can also limit the configuration it can read.

Check three things before confirming:

  • New packages: Do they belong to what you asked for?
  • Proposed removals: Would any named package affect a service or application you still need?
  • Unexpected changes: Can you explain the dependency relationship behind them?

If a service you need appears on a removal list you can't explain, decline the transaction and look into the dependency first.

The -y option accepts confirmation prompts automatically. It reduces your chance to check the proposed changes interactively, although other safety checks can still apply.

Verify the package state and review what changed

APT package verification

Run the same check afterwards. For curl:

apt policy curl

The Installed field shows the installed version. Candidate shows the version APT selects under your package policy. After an install, Installed shows a version, and after a successful removal it shows that the package is no longer installed. After an upgrade, compare it with the version you meant to apply.

To see whether other updates are still available, run:

apt list --upgradable
APT transaction history

APT records past transactions in:

/var/log/apt/history.log

On Ubuntu 26.04 LTS, APT 3.1 supports apt history-list to list transactions and apt history-info ID to inspect one by its transaction ID. These commands were introduced in Ubuntu 25.10, so older APT installations lack them.

Canonical also documents apt history-undo and apt history-rollback, which display the proposed package changes before reversing them. A reversal does not guarantee that application data, configuration or the whole system returns to an earlier state.

APT errors: locks, missing packages, 404s, and repository problems

APT error diagnosis

Each error points to a different check. Note which operation failed and the exact message before trying any repair.

SymptomPossible causeFirst safe check
Could not get lockAnother package process is activeFind out which process holds the lock and whether it is still running
Permission deniedThe operation needs administrative privilegesCheck what access the operation requires
Unable to locate packageName mismatch, unavailable package, or stale/missing metadataCheck the search results and your configured sources
404 Not Found for an archiveStale reference or missing file at a mirrorLook at the failed URL and the package candidate
Missing Release file or NO_PUBKEYRepository configuration or authentication problemFind the affected source and check its trust setup
Unmet dependenciesConflicting requirements or inconsistent package stateLook at the named packages and the changes the repair proposes
APT repository errors

An HTTP 404 can mean a missing package archive or an unavailable repository Release file. The failed URL and your package-source configuration tell you which.

Ubuntu 24.04 LTS and later use the deb822 format by default, in /etc/apt/sources.list.d/ubuntu.sources. Earlier releases used /etc/apt/sources.list.

When another process holds the lock

PackageKit or another package-management service can legitimately own an APT lock. Find the process and let an active transaction finish. Deleting lock files or killing a process you have not identified can damage package-management state.

When repositories or dependencies fail

Repository authentication errors are about source trust. APT verifies signed repository metadata, and the Debian apt-secure manual explains the model. Do not disable signature checks to force an update through.

apt clean deletes downloaded package archives from the cache.

For an inconsistent dependency state, apt --fix-broken install can help once you understand the changes it proposes.

Why apt says packages are kept back

APT kept packages

A package reported as “kept back” was not upgraded by that operation. Three things can cause it:

  • Phased rollout: Ubuntu policy delays the selected update for that system.
  • Explicit hold: An administrator asked to keep the installed version in place.
  • Dependency or repository policy: The candidate upgrade can need changes the chosen command does not allow, or your configured sources can limit it.
APT package holds

To check a specific package, put its actual name in place of curl in the first command:

apt policy curl
apt-mark showhold

The first shows package-policy information, including installed and candidate versions and any phasing indication. The second lists held packages.

Ubuntu phased updates defer some non-security package updates while Canonical rolls them out gradually, so a delayed package can be working as intended. The Canonical phased-update explanation excludes security updates from phasing and says routine rollouts should proceed unless you have a specific reason to override them. Debian systems can implement Ubuntu's rollout policy differently.

apt vs apt-get: which one to use in scripts

APT scripting interface

Use apt for interactive work. For scripts, Debian recommends apt-get and apt-cache, because the higher-level interface can change.

The commands behave differently. apt upgrade can add dependencies, while apt-get upgrade does not add packages. apt-get dist-upgrade can remove packages.

dpkg handles lower-level package operations. It does not replace APT's repository dependency management.

NoScript Team