apt — quick reference
Update and upgrade
Refresh the local package index, then apply upgrades from configured repositories.
| When to use | Command |
|---|---|
| Download latest package lists from repositories | sudo apt update |
| Upgrade installed packages when new versions exist | sudo apt upgrade |
| Upgrade and allow removing conflicting packages if needed | sudo apt full-upgrade |
Install and remove
| When to use | Command |
|---|---|
| Install a package and its dependencies | sudo apt install package_name |
| Install without confirmation prompts | sudo apt install -y package_name |
| Preview install steps without changing the system | sudo apt install --simulate package_name |
| Remove a package but keep configuration files | sudo apt remove package_name |
| Remove a package and its configuration files | sudo apt purge package_name |
| Remove packages auto-installed only as dependencies | sudo apt autoremove |
Search and inspect
| When to use | Command |
|---|---|
| Search package names and descriptions | apt search keyword |
| Show detailed metadata for one package | apt show package_name |
| List installed packages | apt list --installed |
| List packages with upgrades available | apt list --upgradable |
| Show dependency tree for a package | apt depends package_name |
Sources and maintenance
| When to use | Command |
|---|---|
| Open repository source files in an editor | sudo apt edit-sources |
| Reinstall a package over the current version | sudo apt reinstall package_name |
Help and version
| When to use | Command |
|---|---|
| Show built-in usage summary | apt --help |
| Print apt version | apt --version |
apt — command syntax
apt is the unified front end for package management on Debian systems. Synopsis from apt --help on Ubuntu 25.04 (apt 3.0.0):
apt [options] command
Most used commands:
list - list packages based on package names
search - search in package descriptions
show - show package details
install - install packages
reinstall - reinstall packages
remove - remove packages
autoremove - automatically remove all unused packages
update - update list of available packages
upgrade - upgrade the system by installing/upgrading packages
full-upgrade - upgrade the system by removing/installing/upgrading packages
edit-sources - edit the source information fileInstall, remove, and upgrade commands need sudo. apt reads /etc/apt/sources.list and files under /etc/apt/sources.list.d/.
apt — command examples
Essential Refresh the package index
Run apt update before install or upgrade so apt works from current repository metadata.
Run the command:
sudo apt updateSample output (trimmed):
Hit:1 http://archive.ubuntu.com/ubuntu plucky InRelease
Reading package lists...
Building dependency tree...
Reading state information...If this step is skipped, install may not see the newest package version.
Essential Find a package and read its metadata
Search when you know the tool name but not the exact Debian package spelling.
Run the command:
apt search --names-only '^curl$'Sample output:
Sorting...
Full Text Search...
curl/plucky,now 8.12.1-3ubuntu1 amd64 [installed]
command line tool for transferring data with URL syntaxThen inspect details:
apt show curlSample output (trimmed):
Package: curl
Version: 8.12.1-3ubuntu1
Installed-Size: 503 kB
Depends: libc6 (>= 2.38), libcurl4t64 (= 8.12.1-3ubuntu1), zlib1g (>= 1:1.1.4)Depends lists packages apt will pull in automatically on install.
Essential Dry-run an install with --simulate
Preview what apt would install without modifying the system — useful on production hosts.
Run the command:
sudo apt install --simulate treeSample output (trimmed):
Reading package lists...
Building dependency tree...
Reading state information...
Solving dependencies...
Summary:
Upgrading: 0, Installing: 1, Removing: 0, Not Upgrading: 0
Inst tree (2.1.1-2ubuntu3.25.04.2 Ubuntu:25.04/plucky-updates [amd64])Drop --simulate only when you are ready to apply the change.
Common List installed and upgradable packages
apt list filters the local index — faster than scrolling all of dpkg -l when you know a pattern.
Run the command:
apt list --installed 2>/dev/null | head -4Sample output:
Listing...
3cpio/plucky,now 0.5.1-0ubuntu1 amd64 [installed,automatic]
accountsservice/plucky,now 23.13.9-7ubuntu1 amd64 [installed,automatic]
acl/plucky,now 2.3.2-2 amd64 [installed,automatic]Check pending upgrades:
apt list --upgradable 2>/dev/null | head -3Sample output:
Listing...An empty list after the header means everything is current.
Common Inspect dependencies before installing
See libraries and tools a package requires — helpful when planning minimal images.
Run the command:
apt depends curlSample output:
curl
Depends: libc6 (>= 2.38)
Depends: libcurl4t64 (= 8.12.1-3ubuntu1)
Depends: zlib1g (>= 1:1.1.4)For deeper metadata queries, see the apt-cache command.
Common Apply available upgrades
Typical maintenance flow after apt update: upgrade installed packages without installing new ones unless required as upgrades.
Run the command:
sudo apt upgradeSample output varies with pending updates. Review the package list apt prints before confirming. Use sudo apt full-upgrade when release notes mention dependency changes that need removals.
Simulate first on critical servers:
sudo apt upgrade --simulateAdvanced Preview removal impact
Before removing a widely used library, simulate to see the reverse dependency chain apt would satisfy.
Run the command:
sudo apt remove --simulate curlSample output (trimmed):
REMOVING:
curl
Summary:
Upgrading: 0, Installing: 0, Removing: 1, Not Upgrading: 0
Remv curl [8.12.1-3ubuntu1]Your output may list additional dependent packages. Read the full summary before confirming.
Advanced Clean up unused dependencies
After remove or purge, orphaned auto-installed packages may remain until autoremove runs.
Run the command:
sudo apt autoremove --simulateSample output (trimmed):
Reading package lists...
Building dependency tree...
Reading state information...When packages qualify for removal, apt lists them before the summary. Run without --simulate to apply.
apt — when to use / when not
| Use apt when | Use something else when |
|---|---|
| You manage packages on Ubuntu or Debian interactively | You need script-stable output — prefer apt-get in CI |
| You want one command for update, install, search, and show | You install a local .deb file without repos — dpkg |
| You need dependency resolution from configured repositories | You are on RHEL/Fedora — use dnf or yum |
| You want colored progress for day-to-day admin work | You only query cache metadata offline — apt-cache |
apt vs apt-get
| apt | apt-get | |
|---|---|---|
| Audience | Interactive admin sessions | Scripts and automation |
| Output | Progress bars and readable lists | Stable, machine-oriented text |
| Commands | Unified apt install, apt search, … |
Split across apt-get, apt-cache |
| Recommendation | Daily use on Ubuntu/Debian | Cron, cloud-init, Ansible roles |
Both use the same underlying APT libraries and /var/lib/apt cache.
Related commands
Package management workflow on Debian-family systems.
| Command | One line |
|---|---|
| apt | High-level package manager (this page) |
apt-get |
Script-friendly install and update |
aptitude |
Alternative interactive resolver |
Browse the full index in our Linux commands reference.
apt — interview corner
What is the apt command in Linux?
apt (Advanced Package Tool) is the high-level front end for package management on Debian-based systems. It downloads repository indexes, resolves dependencies, installs .deb packages, and removes software — wrapping lower-level tools like dpkg.
Daily admin tasks: sudo apt update, sudo apt upgrade, sudo apt install package.
A strong answer is:
"apt is Debian/Ubuntu's user-facing package manager — update indexes, install with dependencies, upgrade, and remove packages from configured repositories."
What is the difference between apt and apt-get?
Both talk to the same APT stack. apt targets interactive use — clearer progress and combined subcommands. apt-get keeps stable output for scripts and automation.
On Ubuntu 25.04, apt --version reports 3.0.0; prefer apt-get in unattended scripts if parsers depend on exact text.
A strong answer is:
"Same backend — apt is nicer for humans, apt-get is safer for scripts because its output format changes less."
What is the difference between apt update and apt upgrade?
| Command | What it does |
|---|---|
apt update |
Refreshes package lists from repositories — no packages change yet |
apt upgrade |
Installs newer versions of packages already on the system |
Always update first, then upgrade. full-upgrade may remove packages when dependency conflicts require it.
A strong answer is:
"update refreshes the index; upgrade applies new versions to installed packages. I run update before install or upgrade."
How do you preview apt changes without applying them?
Use --simulate (or -s on apt-get) with install, remove, or upgrade:
sudo apt install --simulate package_nameapt prints the Inst / Remv lines and a summary count without modifying /var/lib/dpkg.
A strong answer is:
"apt install --simulate shows what would be installed or removed — I use it on production before committing."
How do you fix apt lock errors?
Could not get lock means another apt/dpkg process holds /var/lib/dpkg/lock* — often an unattended upgrade or a stuck terminal.
Steps:
Find the blocking PID with ps aux piped to grep; the ps command explains BSD versus UNIX options and filtering command lines.
- Wait for the other process, or identify it with
ps aux | grep -E 'apt|dpkg' - If dpkg was interrupted:
sudo dpkg --configure -a - Retry your apt command
Do not delete lock files while a package operation is running.
A strong answer is:
"Another package manager holds the lock — I find the running apt/dpkg, wait or stop it safely, run dpkg --configure -a if needed, then retry."
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Could not get lock |
Concurrent apt/dpkg | Wait; sudo dpkg --configure -a |
Unable to locate package |
Typo or missing repository | apt search; check sources.list |
The following packages have been kept back |
Phased upgrade or pin | apt full-upgrade or review apt-cache policy |
Unmet dependencies |
Broken partial install | sudo apt -f install |
| Warnings about unstable CLI | apt output may change between versions | Use apt-get in scripts |
