Use it to install, upgrade or remove packages on Debian/Ubuntu, or when apt reports held or broken packages.
APT
APT (apt, apt-get, apt-cache) downloads packages from repositories, resolves dependencies and calls dpkg to install them.
1. apt update first.
2. Held or broken → apt-mark showhold, apt -f install.
3. Lock error → ps aux | grep -E 'apt|dpkg' and wait.
4. Simulate: apt -s install <pkg>.
5. History: /var/log/apt/history.log.
apt reads indexes → resolves dependencies → downloads .debs → dpkg installs → triggers run
For Package Management → Debian / Ubuntu → APT, continue with the first unproven Topic check: Refresh/inspect metadata deliberately and record source errors rather than hiding them. If that boundary is healthy, advance to the adjacent check: Compare installed and candidate versions plus origin, pin priority, holds and architecture. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
sources/pinning/holds → repository indexes → APT cache/policy → candidate selection → dependency/conflict solver → transaction plan → download/authentication → dpkg operations → package state → workload verification
Healthy evidence: metadata sources are valid, policy selects the intended candidate, the reviewed plan contains expected changes, dpkg completes and affected workloads validate.
Step 2 Verification and output interpretation Verify boundary
Existing fast checks for this Topic. - Refresh/inspect metadata deliberately and record source errors rather than hiding them.
- Compare installed and candidate versions plus origin, pin priority, holds and architecture.
- Review the exact transaction plan including removals, new dependencies and upgrades.
- After execution, verify dpkg state, package version and workload/service acceptance.
Verification chain. sources/pinning/holds → repository indexes → APT cache/policy → candidate selection → dependency/conflict solver → transaction plan → download/authentication → dpkg operations → package state → workload verification
Step 3 Commands Verify boundary
apt update
apt install nginx
apt policy nginx
apt-mark hold nginx
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: stale cache, pin/hold/phased-update policy or solver removals are missed because only the final apt command output is inspected.
Step 5 Common mistakes Narrow the fault
apt upgradevsfull-upgradedifferences ignored.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
apt-mark showhold lists held packages. "Could not get lock" means another apt (often unattended-upgrades) is running — wait, don't delete the lock. Use apt -s to simulate.
dpkg --audit— half-installed or unconfigured packagesapt policy <pkg> / dnf info <pkg>— installed and candidate versionsdpkg -l <pkg> / rpm -q <pkg>— installed packageapt-cache depends <pkg> / dnf repoquery --requires <pkg>— dependenciesdpkg -S <file> / rpm -qf <file>— package owning a file
ReferenceWhat it is1 section · depth on demand
Core model
Treat APT as a policy and orchestration layer. Show source-list configuration and metadata freshness, then inspect candidate versions and pin priorities before accepting the solver plan. Distinguish update from upgrade/install, simulation/plan from execution, and APT completion from downstream dpkg configuration and workload health. Holds, phased updates, architecture qualifiers and repository priority can explain unexpected candidates.
ReferenceImportant terms & boundaries5 sections · depth on demand
What this shows and what it does not
APT shows repository policy, candidate selection and orchestration only to the observed point; local dpkg success and workload state remain separate things to check.
In depth
APT: upgrade, full-upgrade and removal
APT installs packages from repositories and resolves dependencies. The apt(8) manual page explains the distinctions that matter most:
updatedownloads package lists, and every other command depends on them.upgradeinstalls newer versions, but never removes packages. An upgrade that would require removing something is held back.full-upgrademay remove packages when that's needed to upgrade the system as a whole.removeleaves small configuration files behind, andpurgeremoves those too.autoremoveremoves automatically installed dependencies that nothing needs any more. Packages you installed explicitly are never proposed.pkg=versionorpkg/releaseselects a specific version or release.
Commands
| Task | Command |
|---|---|
| Refresh lists | apt update |
| Safe upgrade | apt upgrade |
| Upgrade, including new dependencies and removals | apt full-upgrade |
| Install a specific version | apt install nginx=1.24.0-2ubuntu7 |
| Install from a specific release (e.g. backports) | apt install -t bookworm-backports pkg or pkg/bookworm-backports |
| Show installed and candidate versions | apt policy nginx |
| List upgradable | apt list --upgradable |
| Hold a package at its version | apt-mark hold pkg |
| Mark as manually installed | apt-mark manual pkg |
apt or apt-get
| Context | Use |
|---|---|
| Interactive work | apt (progress bars, colours) |
| Scripts, Ansible, Dockerfiles | apt-get / apt-cache (a stable interface) |
| Non-interactive installs | DEBIAN_FRONTEND=noninteractive apt-get -y install ... |
"The following packages have been kept back"
This message means upgrade refused to install a package, because doing so would need new dependencies or removals. Run full-upgrade after reviewing what it would do. Phased updates on Ubuntu can also hold packages back temporarily, which is intended behaviour.
host$ sudo apt update
host$ apt list --upgradable 2>/dev/null | wc -l
14
host$ sudo apt upgrade
The following packages have been kept back:
linux-generic linux-headers-generic linux-image-generic
host$ sudo apt full-upgrade --dry-run | grep -E "^(Inst|Remv)" | head
host$ apt policy nginx
nginx:
Installed: 1.24.0-2ubuntu7
Candidate: 1.24.0-2ubuntu7.1
host$ sudo apt-mark hold postgresql-16 && apt-mark showhold
host$ sudo apt autoremove --purge
Reading the example
The kernel metapackages were kept back because they pull in new kernel packages. full-upgrade --dry-run shows the planned installs and removals first. A held package, here postgresql-16, stays at its current version until it's released with apt-mark unhold.
Documented example, not captured output.
How it works at runtime
APT is part of Package Management → Debian / Ubuntu → APT. APT is Debian-family repository-aware package management: it downloads repository indexes, computes candidates using version/pinning rules, resolves dependencies/conflicts and orchestrates dpkg transactions for install, upgrade and removal operations.
Topic-specific state model. APT is Debian-family repository-aware package management: it downloads repository indexes, computes candidates using version/pinning rules, resolves dependencies/conflicts and orchestrates dpkg transactions for install, upgrade and removal operations.
Interpretation rule. - apt update success ≠ packages upgraded.
- Candidate version ≠ installed version.
- Solver plan ≠ committed dpkg transaction.
- APT exit 0 ≠ application acceptance test passed.
Quick reference
APT details:
apt policy nginx # candidate version and pin priorities
apt-cache depends nginx; apt-cache rdepends nginx
apt install nginx=1.24.0-2ubuntu7 # specific version
apt autoremove --purge
apt-get -s upgrade # simulate
apt-get -o Dpkg::Options::='--force-confold' -y upgrade # keep local configs (automation)
cat /var/log/apt/history.log
Pinning (/etc/apt/preferences.d/) controls which repository wins. Lock errors (/var/lib/dpkg/lock-frontend) usually mean unattended-upgrades is running — wait rather than deleting locks.
Limits and how it fails
Primary failure point. APT shows repository policy, candidate selection and orchestration only to the observed point; local dpkg success and workload state remain separate things to check.
ReferenceConfiguration & state1 section · depth on demand
Configuration, persistence and lifecycle
Distribution/platform context. APT owns Debian-family repository policy, candidate/dependency solving and dpkg orchestration. dpkg command semantics remain an existing Command leaf; repository trust/config lives in Debian/Ubuntu Repositories.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Package Management → Debian / Ubuntu → APT. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.debian.org/doc/manuals/debian-reference/ch02.en.html · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
APT operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for APT.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | APT is Debian-family repository-aware package management: it downloads repository indexes, computes candidates using version/pinning rules, resolves dependencies/conflicts and orchestrates dpkg transactions for install, upgrade and removal operations. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin host + distribution/release + architecture → identify exact package/version request → enumerate effective repositories/trust → refresh/inspect metadata → compare installed versus candidate/origin → review dependency/conflict transaction → capture package-manager transaction → verify local package database/files/scripts → inspect service/reboot/config effects → repeat original workload test. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | sources/pinning/holds → repository indexes → APT cache/policy → candidate selection → dependency/conflict solver → transaction plan → download/authentication → dpkg operations → package state → workload verification | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | APT proves repository policy, candidate selection and orchestration only to the observed point; local dpkg success and workload state remain separate boundaries. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux package-management evidence can establish this proof path: sources/pinning/holds → repository indexes → APT cache/policy → candidate selection → dependency/conflict solver → transaction plan → download/authentication → dpkg operations → package state → workload verification | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove behavior outside the captured repository, solver, transaction, local package database, runtime-side-effect or workload scope. APT proves repository policy, candidate selection and orchestration only to the observed point; local dpkg success and workload state remain separate boundaries. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven boundary: confirm distribution/release and repository trust, inspect candidate/origin and solver policy, correlate the package-manager transaction with dpkg/RPM local state, then test affected services and the original workload before making additional package changes. | Continue to the next unresolved boundary while preserving the original test condition. |
APT · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | APT |
|---|---|
| Topic path | Package Management → Debian / Ubuntu → APT |
| Runtime state | APT is Debian-family repository-aware package management: it downloads repository indexes, computes candidates using version/pinning rules, resolves dependencies/conflicts and orchestrates dpkg transactions for install, upgrade and removal operations. |
| Fast checks | - Refresh/inspect metadata deliberately and record source errors rather than hiding them. - Compare installed and candidate versions plus origin, pin priority, holds and architecture. - Review the exact transaction plan including removals, new dependencies and upgrades. - After execution, verify dpkg state, package version and workload/service acceptance. |
| Verification chain | sources/pinning/holds → repository indexes → APT cache/policy → candidate selection → dependency/conflict solver → transaction plan → download/authentication → dpkg operations → package state → workload verification Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary. |
| Failure boundary | APT proves repository policy, candidate selection and orchestration only to the observed point; local dpkg success and workload state remain separate boundaries. Boundary chain: repository/metadata → dependency resolution → artifact/signature → package database/file install → scriptlets → service/process reload → effective binary/config → workload. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |