apt command in linux with examples

apt provides a high-level CLI (Command Line Interface) for the package management system and is intended as an interface for the end user which enables some options better suited for interactive usage by default compared to more specialized APT tools like apt-cache and apt-get.

Syntax:

apt [...COMMANDS] [...PACKAGES]

Most Used Commands:

  • update : This command is used when we want to download package information from all configured sources.

    Syntax:

    apt update
  • upgrade : This command is used when we want to install available upgrades of all packages currently installed on the system from the sources configured via sources.list. If new packages are required to satisfy dependencies, they will be installed, but already existing packages will never be removed. If for a package to be upgraded, the removal of an installed package is required, the upgrade will not be performed.

    Syntax:

    apt upgrade
  • full-upgrade : This command has a functionality similar to upgrade but if to upgrade the system as a whole, if the removal of already installed packages is required, then it will remove them.

    Syntax:

    apt full-upgrade
  • install : This command performs the action of installation on one or more packages specified via regex, glob or exact match. The user can select a specific version of the package to be installed by following the package name with ‘equals’ sign and specifying the version number. Also, the user can specify the version from a specific release by following the package name with a forward slash (/) and the codename (stretch, buster, sid, etc.) or the suite name (stable, testing, unstable).

    Syntax:

    apt install [...PACKAGES]
  • remove : This command is similar to install command, the only difference being that the remove command removes the packages instead of installing them.

    Syntax:

    apt remove [...PACKAGES]
  • purge : This command is similar to remove command, the only difference being that the purge command also removes any configuration files related to the removed packages.

    Syntax:

    apt purge [...PACKAGES]
  • autoremove : This command is used when the user wants to remove the packages that were installed as dependencies to previously installed packages, and are no longer required by the system, as the packages which required them as dependencies were removed, or the dependencies were changed. The packages which the user explicitly installs via apt install are never proposed for automatic removal.

    Syntax:

    apt autoremove
  • search : This command is used when the user wants to search for the given regex term(s) in the list of available packages and display matches. For example, this command can be useful when you want to search for packages having a specific feature.

    Syntax:

    apt search [...REGEX]
  • show : This command is used when the user wants to display information regarding packages like it’s dependencies, download and installation size, the sources from which the package is available, the package’s content’s description and more. It can be helpful to display the information before the user removes the package, or while searching for a package to install.

    Syntax:

    apt show [...PACKAGES]

    Output:

  • list : This command is used to display a list of packages that satisfy a certain criteria. It is similar to dpkg-query –list in that manner. It has a support for glob patterns for matching the package names and options to list the installed (–installed), upgradeable (–upgradeable) or all-available versions (–all-versions).

    Syntax:

    apt list [--installed/--upgradeable/--all-versions]
  • edit-sources : This command lets you edit your sources.list files in your preferred text editor and also provides basic sanity checks.

    Syntax:

    apt edit-sources

Options:

  • –help : Display an overview of functionalities, and related help.

    Syntax:

    apt --help

  • –version : Display the current version number.

    Syntax:

    apt --version

    Output:



  • My Personal Notes arrow_drop_up

    Full stack web developer | GCI 18 Mentor | JSec at IIITV Coding Club

    If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

    Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.