« Back to Cheat sheets

apt cheat sheet

This cheat sheet helps becoming more fluent with the apt command, the package manager used on Linux systems running Debian, Ubuntu, and others.

Basic usage

These are common subcommands to be used together with apt:

CommandIntended action
autoremoveClean up packages that are no longer needed
install PACKAGEInstall package
search PATTERNSearch for available package according to the pattern
purge PACKAGERemove the remainders after removing a package
remove PACKAGERemove package, leave custom configurations
show PACKAGEProvide information about a package
updateRefresh the repository data
upgradePull in and install upgrades for packages that are installed

Common options include:

--yes-yPerform ‘yes’ to prompts, automating actions

Information about packages

See which packages are available that start with ’nginx’ with the list subcommand and really quiet output.

# apt -qq list nginx*
nginx-common/jammy-updates 1.18.0-6ubuntu14.4 all
nginx-confgen/jammy 2.0-1 amd64
nginx-core/jammy-updates 1.18.0-6ubuntu14.4 amd64
nginx-doc/jammy-updates 1.18.0-6ubuntu14.4 all
nginx-extras/jammy-updates 1.18.0-6ubuntu14.4 amd64
nginx-full/jammy-updates 1.18.0-6ubuntu14.4 amd64
nginx-light/jammy-updates 1.18.0-6ubuntu14.4 amd64
nginx/jammy-updates 1.18.0-6ubuntu14.4 amd64

Show information of a single package to learn what it does, its dependencies, size, and other possible relevant information.

apt show nginx

Installed packages

See all installed packages with the list subcommand and --installed option.

apt list --installed

Installation of packages

Installation happens with the subcommand install followed by the package.

apt install nginx

Install a local .deb file is also possible.

apt install myfile.deb

Upgrading packages

Refresh the repository to pull in the latest available information of the underlying databases.

apt update

See packages that have a newer version (upgrade):

apt list --upgradable

Install available upgrades:

apt upgrade

Use apt-file to see to which package a file belongs or what files are provided by a package.

Relevant articles using apt command

The following articles include an example on how to use apt and might be worth further exploring.

Liked this cheat sheet? There are more!


Small picture of Michael Boelen

This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

Mastodon icon