Linux apt command

Updated: 02/01/2021 by Computer Hope
apt command

On Linux operating systems that use the APT package management system, the apt command installs, removes, upgrades, and manages software packages. It automatically manages package dependencies, installing required software as needed, and removing it when no longer required.

Description

The apt command performs a similar function to apt-get, but with some additional functions, conveniences, and features. For instance, it provides colorization and fancier formatting of text output, and an animated progress bar when installing software. However, these formatting changes make apt unsuitable for capturing output to a file, or processing it with another tool such as grep. If you need to save or process the output of apt, it's a good idea to use apt-get instead.

Apt is available on several modern Linux distributions, primarily Debian and Ubuntu. It is also available on Windows 10 systems that use the default Ubuntu Windows Subsystem for Linux.

Syntax

apt [-h] [-o=config_string] [-c=config_file] [-t=target_release]
    [-a=architecture] {list | search | show | update |
    install pkg [{=pkg_version_number | /target_release}]... |
    remove pkg... | upgrade | full-upgrade | edit-sources | 
    {-v | --version} | {-h | --help}}

Commands

Tip

Any commands listed below that make changes to your system must be run by the superuser, or with the sudo command.

update The update command downloads up-to-date information about available software packages. This information is used by apt to perform most of its other operations, including installation, upgrading, dependency management, and listing package information.

An update should always be run before an upgrade or a full-upgrade.
upgrade pkg Install the upgraded versions of package pkg. If no package is specified, all currently-installed packages are upgraded.
full-upgrade Perform an upgrade, but also remove outdated or incompatible packages, if necessary, to fully upgrade the system. This is the equivalent of apt-get dist-upgrade.
install pkg Installs the package named pkg. The name pkg can be the exact name of a package, a regular expression, or use wildcards.

In this command, and with remove and purge, you can specify multiple package names with a plus sign ("+") or a minus sign ("-") at the end of the name to mark it for installation or removal. You can also append an equals sign ("=") at the end of the name, followed by a specific version number, to apply the command only to that version of the software. If you add a slash ("/") followed by a release codename of your Linux distribution, apt uses the software package from that release. See examples, below.
remove pkg Uninstall the software package named pkg, but do not remove any configuration files that might have been modified on your system. Similar to install, regular expressions or wildcards can specify pkg; the +, - symbols can be appended to the package name to specify installation or removal; = and / symbols can be appended to specify software version or release codename.
purge pkg Uninstall pkg, and purge any associated configuration files. Similar to install, regular expressions or wildcards can specify pkg; the +, - symbols can be appended to the package name to specify installation or removal; = and / symbols can be appended to specify software version or release codename.
autoremove The autoremove command removes any packages that were previously required as dependencies of other software, which are no longer required. Running this command periodically will conserve disk space. If packages are eligible for autoremoval, they are reported when you perform other operations such as apt update.

If a software package is marked for autoremoval because it is no longer required, but you'd like to keep it, you can mark it manually installed using the command apt-mark.
search text Search for available packages whose names or descriptions contain the text text, which can include regular expressions and wildcards. This is the equivalent of apt-cache search. If you're looking for a package which contains a certain file, you can use the command apt-file.
show pkg Display information about pkg, including a brief description, what its dependencies are, and how much disk space the package requires. Regular expressions and wildcards may be used in the package name. This command is equivalent to apt-cache show.
list List packages that meet a certain set of criteria. With no other options, lists all available package names. With the option --all-versions, lists all available versions of all packages. With --installed, lists all currently-installed packages, similar to dpkg --list. With --upgradable, lists all installed packages that can be upgraded.
edit-sources Opens your list of package sources in a text editor, and checks the file for errors after you save and close it. Editing your sources list changes the Internet location where apt gets information about, and downloads, software packages.

Options

-v, --version Display information about what version of apt you are using.
-h, --help Display a brief listing of available commands and options.
-y Assume the answer "yes" to any prompts, proceeding with all operations if they are possible.
--assume-no Assume the answer "no" to all prompts.
-d,
--download-only
For any operation that would download packages, download them, but do nothing else.
-f,
--fix-broken
When used with install or remove, this option attempts to fix any broken dependencies.
--no-download Do not download any packages. This forces apt to use only packages it has already downloaded.
-s,
--simulate
Simulate operations, reporting what they would do, but make no changes to the system.

Examples

sudo apt update && sudo apt upgrade

Update information about available packages, and then upgrade all installed packages on your system. You will be prompted before installation begins.

sudo apt update && sudo apt -y upgrade

Same as above, but automatically answer yes to the prompt.

sudo apt install vim

Install the vim software package and its dependencies.

sudo apt install "vim*"

Install any packages whose name starts with "vim". The package name is enclosed in quotes to make sure the wildcard ("*", meaning match anything) is passed to apt rather than interpreted by the shell.

apt show fortune

Display information about the package named fortune.

sudo apt install lolcat vim-gnome-

Install the package lolcat, and remove the package vim-gnome.

sudo apt remove lolcat+ vim-gnome

Remove the package vim-gnome, and install the package lolcat.

apt list --all-versions zypper

List all available versions of the software package zypper.

sudo apt install zypper=1.12.4-1

Install version 1.12.4-1 of zypper.

sudo apt install zypper/xenial

On Ubuntu, install the default version of zypper provided by Ubuntu 16.04, whose codename is xenial.

apt-cache — Get information about software packages available through APT.
apt-file — Search for individual files in all available APT packages.
apt-get — Command line tool for managing APT software packages.
apt-mark — Change or view the settings of individual APT packages.
aptitude — Text-based front end for the APT package management system.
dpkg — Install, remove, and maintain Debian software packages.