The apt command

command-line interface 22 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.

Subcommands in the examples

apt install
Performs the requested action on one or more packages specified via regex(7), glob(7) or exact match.
apt list
list is somewhat similar to dpkg-query --list in that it can display a list of packages satisfying certain criteria.
apt update
update is used to download package information from all configured sources.
apt autoremove
autoremove is used to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer…
apt autoclean
apt remove
Performs the requested action on one or more packages specified via regex(7), glob(7) or exact match.
apt search
search can be used to search for the given regex(7) term(s) in the list of available packages and display matches.
apt upgrade
upgrade is used to install available upgrades of all packages currently installed on the system from the sources configured via…
apt full-upgrade
full-upgrade performs the function of upgrade but will remove currently installed packages if this is needed to upgrade the system as a…
apt purge
Performs the requested action on one or more packages specified via regex(7), glob(7) or exact match.
apt show
Show information about the given package(s) including its dependencies, installation and download size, sources the package is available…

Examples

sudo apt update
apt list --upgradable
sudo apt upgrade

Upgrade everything that's safe to upgrade

sudo apt full-upgrade

Also handles dependency changes (may remove packages)

apt --version
sudo apt install htop
sudo apt install htop tree curl

Multiple at once

sudo apt install -y htop

Auto-confirm prompts

sudo apt remove htop

Removes the program, keeps config files

sudo apt purge htop

Removes the program AND its config files

sudo apt autoremove

Removes packages that were only installed as dependencies and are no longer needed

sudo apt autoclean

Clears out old downloaded .deb files from cache

sudo apt install --reinstall htop
sudo apt install nginx
sudo apt remove --purge htop
apt search nginx
apt search "web server"
apt show nginx
apt list --installed
apt list --installed | grep nginx
sudo apt install -f

"Fix" — installs missing dependencies

sudo apt install git

Make sure git is available

Lessons that use apt

Related commands