The Short Answer
apt and apt-get do the same job with the same package system: they install, update, and remove .deb packages on Debian and Ubuntu. Use apt when you type commands yourself, and apt-get, with apt-cache for searches, in scripts, because only the older tools keep their output the same between versions.
Same Engine Underneath
Both commands are front ends to the same library. They read the same repository lists in /etc/apt/sources.list and /etc/apt/sources.list.d/, share one package cache, and record installs in the same dpkg database. A package installed with one can be upgraded or removed with the other.
apt was added to combine the most used parts of apt-get and apt-cache in one shorter command with friendlier output: a progress bar, colors, and a note after apt update about how many packages can be upgraded.
Commands Side by Side
| apt | apt-get or apt-cache |
|---|---|
apt update | apt-get update |
apt install nginx | apt-get install nginx |
apt remove nginx | apt-get remove nginx |
apt purge nginx | apt-get purge nginx |
apt upgrade | apt-get upgrade --with-new-pkgs |
apt full-upgrade | apt-get dist-upgrade |
apt autoremove | apt-get autoremove |
apt search nginx | apt-cache search nginx |
apt show nginx | apt-cache show nginx |
apt policy nginx | apt-cache policy nginx |
Two apt commands have no apt-get form: apt list --upgradable lists pending updates, and apt list --installed lists installed packages, much like dpkg -l. Commands that change the system need sudo.
upgrade, full-upgrade, and dist-upgrade
apt-get upgrade: upgrades installed packages but never installs a new package or removes one. An update that needs a new dependency is held back.apt upgrade: also installs new dependencies when needed, but never removes a package.apt full-upgradeandapt-get dist-upgrade: the same operation, which may also remove packages to resolve conflicts. Read the list of removals before you answer yes.
Despite its name, dist-upgrade does not move you to a new release; on Ubuntu that is do-release-upgrade, covered in how to upgrade Ubuntu. Day-to-day updating is in sudo apt update.
The Warning apt Prints in Scripts
When apt's output goes to a pipe or a file instead of a terminal, apt prints a warning that it does not have a stable command-line interface and should be used with caution in scripts. The warning is accurate: the layout of apt's output may change in a new version, while apt-get keeps its format. A script that installs packages should use apt-get:
#!/bin/bash
set -e
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y nginx
-y answers yes to the confirmation, and DEBIAN_FRONTEND=noninteractive stops packages from asking configuration questions that would wait forever. The same lines belong in a Dockerfile. Script basics are in how to write a Bash script.
Which One to Use Where
- At the terminal:
apt. - In scripts, cron jobs, Dockerfiles, and provisioning tools:
apt-get. - When a script reads package data:
apt-cacheordpkg-query, whose output is meant for parsing. - In instructions you follow: either works; swap them using the table above.
Common Problems with Both
Both stop when another package process holds the lock; see could not get lock, and do not delete the lock files by hand. A local .deb file is installed with sudo apt install ./file.deb, as shown in how to install .deb files in Ubuntu. On AlmaLinux and Rocky Linux the equivalent tool is dnf; see DNF vs YUM. For the other package format on Ubuntu, read snap vs apt.