apt Command in Linux

apt (short for Advanced Package Tool) is a command-line utility for installing, updating, removing, and otherwise managing deb packages on Ubuntu, Debian, and related Linux distributions. It combines the most frequently used commands from the apt-get and apt-cache tools with different default values of some options.
apt is designed for interactive use. Prefer using apt-get and apt-cache in your shell scripts as they are backward compatible between the different versions and have more options and features.
Most of the apt commands must be run as a user with sudo
privileges.
This guide explains the most common apt commands for day-to-day package management.
For a closer look at updating your system, see apt update vs apt upgrade vs apt full-upgrade .
Updating Package Index (apt update)
The APT package index is a database that holds records of available packages from the repositories enabled in your system.
To update the package index, run the command below. This will pull the latest changes from the APT repositories:
sudo apt updateThe output will look something like this:
Hit:1 https://deb.debian.org/debian trixie InRelease
Hit:2 https://deb.debian.org/debian trixie-updates InRelease
Hit:3 https://deb.debian.org/debian trixie-backports InRelease
Get:4 https://deb.debian.org/debian-security trixie-security InRelease [43.4 kB]
Get:5 https://deb.debian.org/debian-security trixie-security/main Sources [268 kB]
Get:6 https://deb.debian.org/debian-security trixie-security/main arm64 Packages [306 kB]
Get:7 https://deb.debian.org/debian-security trixie-security/main Translation-en [184 kB]
Fetched 802 kB in 0s (2327 kB/s)
10 packages can be upgraded. Run 'apt list --upgradable' to see them.Each Hit line means the repository file has not changed since your last update. A Get line means APT downloaded a newer copy. The last line tells you how many installed packages have newer versions available. apt update only refreshes the index and does not install anything.
Always update the package index before upgrading or installing new packages.
Installing Packages (apt install)
Installing packages is as simple as running the following command:
sudo apt install package_nameIf you want to install multiple packages with one command, specify them as a space-separated list:
sudo apt install package1 package2To install local deb files , provide the full path to the file. Otherwise, the command will try to retrieve and install the package from the APT repositories.
sudo apt install /full/path/file.debFor a file in the current directory, prefix the name with ./:
sudo apt install ./file.debWithout the ./ prefix, apt treats the file name as a package name and fails with Unable to locate package.
To install a specific version of a package, append the version string to the package name. Run apt policy package_name first to see which versions the enabled repositories offer:
sudo apt install package_name=versionWhen the same package is available from more than one release, you can append the release name to select that version. For example, this command installs a package from Debian backports while preferring dependencies from the default release:
sudo apt install package_name/trixie-backportsThe -t option (long form --target-release) sets a target release for the entire transaction. This can pull additional dependencies from backports, so use it when the selected package requires them:
sudo apt install -t trixie-backports package_nameUpgrading Packages (apt upgrade)
Regularly updating your Linux system is one of the most important aspects of overall system security.
To upgrade the installed packages to their latest versions run:
sudo apt upgradeThe command can install new dependencies when an upgrade needs them, but it never removes installed packages. If upgrading a package would require removing another one, apt upgrade skips it.
To upgrade one already-installed package without installing it if it is absent, use install with --only-upgrade:
sudo apt install --only-upgrade package_nameIt is always a good idea to configure automatic security updates .
Full Upgrading (apt full-upgrade)
The difference between upgrade and full-upgrade is that the latter will remove installed packages if that is needed to upgrade the whole system.
sudo apt full-upgradeBe extra careful when using this command.
Skipping the Confirmation Prompt
Before it changes anything, apt shows what it plans to do and waits for you to type Y. The -y option (long form --yes) answers that prompt in advance. Use it when you already know and trust the proposed transaction:
sudo apt install -y package_nameThe same option works with the upgrade commands:
sudo apt upgrade -ysudo apt full-upgrade -yA common one-liner refreshes the package index and upgrades everything in a single step:
sudo apt update && sudo apt upgrade -yThe -y in that line applies only to the second command. Although apt update does not normally prompt, it can request confirmation when repository release information changes, so the one-liner is not guaranteed to run unattended. Review the proposed changes before using -y, even with install, because resolving package conflicts can remove installed packages. For scripts and Dockerfiles, use apt-get
rather than apt, as its output format stays stable across versions.
Reinstalling a Package (apt install –reinstall)
If a package is broken or you want to restore its files, reinstall it with:
sudo apt install --reinstall package_nameFixing Broken Dependencies
When an installation is interrupted, or a package is installed with dpkg, which does not resolve dependencies on its own, you can end up with packages that are unpacked but not configured. In that state apt refuses to continue and points you at the fix:
You might want to run 'apt --fix-broken install' to correct these.
Unsatisfied dependencies:
example-app : Depends: libexample2 but it is not going to be installed
Error: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).The Unsatisfied dependencies: list names the broken package and the dependency it is missing. The package names in this example are placeholders. APT versions older than 3.0, such as the ones in Ubuntu 24.04 and Debian 12, print The following packages have unmet dependencies: above the list and start the last line with E:.
Run the command with no package name to install whatever is missing and finish the configuration:
sudo apt install -fThe -f option is short for --fix-broken, so sudo apt --fix-broken install does the same thing. This is also the standard follow-up after installing a deb file
with dpkg -i.
If the repair fails, see our guide on fixing broken packages on Ubuntu for held packages, repository conflicts, and package-specific repairs.
Removing Packages (apt remove)
To remove an installed package type the following:
sudo apt remove package_nameYou can also specify multiple packages, separated by spaces:
sudo apt remove package1 package2The remove command will uninstall the given packages, but it may leave some configuration files behind. If you want to remove the package including all configuration files, use purge instead of remove:
sudo apt purge package_nameRemoving Unused Packages (apt autoremove)
Whenever a new package that depends on other packages is installed on the system, the package dependencies will be installed too. When the package is removed, the dependencies will stay on the system. These leftover packages are no longer used by anything else and can be removed.
To remove the unneeded dependencies use the following command:
sudo apt autoremoveTo remove unused packages and their configuration files, run:
sudo apt autoremove --purgeListing Packages (apt list)
The list command allows you to list the available, installed, and upgradable packages. Like search, show, and policy, it only reads package data that is already on disk, so it does not need sudo.
To list all available packages use the following command:
apt listThe command will print a list of all packages, including information about the versions and architecture of the package. On APT 3.0 and newer, long output opens in a pager that you can close with q.
To find out whether a specific package is installed, pass its name to apt list. You can use wildcards in the name. Quote the pattern so the shell does not expand it:
apt list --installed 'openssh*'openssh-client/stable,now 1:10.0p1-7+deb13u4 arm64 [installed,automatic]
openssh-server/stable,now 1:10.0p1-7+deb13u4 arm64 [installed]
openssh-sftp-server/stable,now 1:10.0p1-7+deb13u4 arm64 [installed,automatic]Each line shows the package name, the release it comes from, the version, and the architecture. [installed] marks a package you installed yourself. [installed,automatic] marks a dependency that APT pulled in. Once nothing depends on it, apt autoremove can remove it.
You can also filter the full list with the grep
command. When the output goes to a pipe, apt prints a warning that its command-line interface is not stable. The warning is harmless for interactive use:
apt list | grep package_nameTo list only the installed packages type:
apt list --installedGetting a list of the upgradable packages may be useful before actually upgrading the packages:
apt list --upgradableSearching Packages (apt search)
This command allows you to search for a given package in the list of the available packages:
apt search package_nameThe search term is a regular expression that apt search matches against both package names and descriptions. If a short term returns hundreds of results, you can limit the search to package names with the --names-only option:
apt search --names-only package_namePackage Information (apt show)
The information about the package dependencies, installation size, the package source, and so on might be useful before removing or installing a new package.
To retrieve information about a given package, use the show command:
apt show package_namePackage Policy (apt policy)
Use apt policy to see which version will be installed and which repositories it comes from:
apt policy package_nameThis is helpful when troubleshooting version conflicts or pinned packages.
Cleaning Package Cache (apt clean / apt autoclean)
To remove cached package files and free disk space, use:
sudo apt cleanTo remove only outdated cached packages, use:
sudo apt autocleanapt deletes the downloaded .deb files after a successful installation. apt-get keeps them in /var/cache/apt/archives until you clean the cache. If you install packages only with apt, you will rarely need to run these commands.
Troubleshooting
APT 3.0 and newer (Ubuntu 25.04 and later, Debian 13) start error messages with Error: and warnings with Warning:. Older releases and apt-get print E: and W: instead.
Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend
Another process is already using the package system, usually unattended-upgrades or a package manager left open in another window. By default, apt waits indefinitely for the lock when its standard input is a terminal. Otherwise, it waits up to two minutes and then exits with Unable to acquire the dpkg frontend lock. apt-get does not wait by default and fails at once with E: Could not get lock. If the wait times out, let the other process finish and run the command again. If the process appears frozen, identify it with sudo lsof /var/lib/dpkg/lock-frontend, terminate it gracefully, and run sudo dpkg --configure --pending to finish any interrupted configuration. Never delete dpkg lock files by hand, as doing so can corrupt the package database or filesystem. Our guide to APT and dpkg lock errors
covers the full diagnostic process.
Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
The command changes the system and needs root privileges, so prefix it with sudo. Read-only commands such as apt list and apt search do not need it. Running apt update without sudo fails with the same error for /var/lib/apt/lists/lock.
Unable to locate package
Either the package index is out of date or the package is not in the repositories you have enabled. Run sudo apt update first. If the package is still not found, it may live in a repository that is not enabled on your system, such as universe on Ubuntu, or in a third-party repository
you have to add yourself. The Unable to locate package guide
covers package names, release and architecture checks, and enabling missing components.
GPG error and NO_PUBKEY
The public signing key for one of your repositories is missing or unavailable to APT, so it will not trust that repository’s package list. Download the current key from the repository provider, store it under /etc/apt/keyrings, and point the repository entry at that file with the signed-by option. The NO_PUBKEY error guide
covers fingerprint verification, DEB822 sources, and keyserver fallback.
Packages kept back or not upgraded
On APT 3.0 and newer, apt upgrade shows these packages under Not upgrading:. Older releases print The following packages have been kept back:. On Ubuntu, this often means that an update is being released gradually through phased updates. Those packages appear under Not upgrading yet due to phasing:. Run apt policy package_name and look for a phased percentage. If the package is phased, wait and APT will install it when the update reaches your system. Packages can also be kept back because of dependency changes or package holds. Do not jump directly to full-upgrade; use it only when the proposed solution genuinely requires removals, and read the removal list before confirming.
Quick Reference
For a printable quick reference, see the APT cheatsheet .
| Command | Description |
|---|---|
sudo apt update | Refresh the package index |
sudo apt install <pkg> | Install a package |
sudo apt install -y <pkg> | Install without the confirmation prompt |
sudo apt install <pkg>=<version> | Install a specific version |
sudo apt install -f | Fix broken dependencies |
sudo apt upgrade | Upgrade all installed packages |
sudo apt full-upgrade | Upgrade, removing packages if needed |
sudo apt remove <pkg> | Remove a package (keep config files) |
sudo apt purge <pkg> | Remove a package and its config files |
sudo apt autoremove | Remove unused dependency packages |
apt list --installed | List installed packages |
apt list --upgradable | List packages with pending upgrades |
apt search <pkg> | Search for a package |
apt show <pkg> | Show package details |
apt policy <pkg> | Show available versions and sources |
sudo apt clean | Remove all cached package files |
sudo apt autoclean | Remove outdated cached packages |
FAQ
What does apt stand for?
APT is short for Advanced Package Tool, the package management system used by Debian and the distributions built on it. The apt command is the front end you type at the terminal, while apt-get, apt-cache, and apt-mark are separate tools that belong to the same system.
How do I install apt?
APT is installed by default on Debian, Ubuntu, and distributions built on them, such as Linux Mint, so you normally do not need to install it. If the shell reports apt: command not found, check your distribution with cat /etc/os-release. On Debian or Ubuntu, check that /usr/bin/apt exists and /usr/bin is in your PATH. Use dnf
on Fedora and RHEL, pacman on Arch Linux, or zypper on openSUSE.
What does sudo apt do?sudo runs the command that follows it with root privileges, and apt is the package manager. Every apt command that changes the system, such as install, remove, upgrade, or update, needs those privileges, which is why most of the examples above start with sudo.
Do apt search, apt list, and apt show require sudo?
No. Those commands only read package data that is already on your disk, so any user can run them. Adding sudo does not change what they return.
Is it safe to use apt install -y?
It is safe when you know what changes APT will make. The -y option skips the normal confirmation, and even installing a named package can remove conflicting packages. Run the command without -y first when you are unsure, then review the package list before confirming or adding the option to controlled automation.
What is the difference between apt update and apt upgrade?apt update refreshes the local record of which packages and versions are available and installs nothing. apt upgrade installs the newer versions that the refreshed record revealed. Run update first, otherwise upgrade works from stale information.
Conclusion
For day-to-day package management, sudo apt update followed by sudo apt upgrade covers most of what you need. For a comparison of when to use apt versus apt-get in scripts, see apt vs apt-get: What Is the Difference?
.
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page