apt Command in Linux

apt 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.
Updating Package Index (apt update)
The APT package index is basically 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 updateAlways 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.debUpgrading 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 does not upgrade packages that require removal of installed packages.
If you want to upgrade a single package, pass the package name:
sudo apt 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.
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_nameRemoving 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_nameRemove 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.
To list all available packages use the following command:
sudo apt listThe command will print a list of all packages, including information about the versions and architecture of the package. To find out whether a specific package is installed, you can filter the output with the grep
command.
sudo apt list | grep package_nameTo list only the installed packages type:
sudo apt list --installedGetting a list of the upgradable packages may be useful before actually upgrading the packages:
sudo apt list --upgradeableSearching Packages (apt search)
This command allows you to search for a given package in the list of the available packages:
sudo apt search package_nameIf found, the command will return the packages whose name matches the search term.
Package 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:
sudo apt show package_namePackage Policy (apt policy)
Use apt policy to see which version will be installed and which repositories it comes from:
sudo 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 autocleanQuick 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 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 |
sudo apt list --installed | List installed packages |
sudo apt search <pkg> | Search for a package |
sudo apt show <pkg> | Show package details |
sudo apt policy <pkg> | Show available versions and sources |
sudo apt clean | Remove all cached package files |
sudo apt autoclean | Remove outdated cached packages |
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 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page