English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux apt Command

apt (Advanced Packaging Tool) is a Shell frontend package manager in Debian and Ubuntu.

apt commands provide commands to search for, install, upgrade, delete a single, a group, or even all software packages, and the commands are concise and easy to remember.

Executing apt commands requires superuser privileges (root).

apt syntax

  apt [options] [command] [package ...]
  • options:Optional, options include -h (help),-y (when the installation process prompts to choose all as "yes"),-q (do not display the installation process), etc.

  • command:The operation to be performed.

  • package: The name of the installed package.

Common apt commands

  • List all upgradable software packages command: sudo apt update

  • Upgrade software packages: sudo apt upgrade

    List upgradable software packages and version information: apt list --upgradeable

    Upgrade software packages, delete the software packages that need to be updated before upgrading: sudo apt full-upgrade

  • Install a specified software command: sudo apt install <package_name>

    Install multiple software packages: sudo apt install <package_1> <package_2> <package_3>

  • Update a specified software command: sudo apt update <package_name>

  • Display detailed information of the software package, such as: version number, installation size, dependencies, etc.: sudo apt show <package_name>

  • Delete software package commands: sudo apt remove <package_name>

  • Clean up unused dependencies and library files: sudo apt autoremove

  • Remove the software package and configuration files: sudo apt purge <package_name>

  • Search for software package commands: sudo apt search <keyword>

  • List all installed packages: apt list --installed

  • List the version information of all installed packages: apt list --all-versions

Online example

View some upgradable packages:

sudo apt update

Upgrade the installed package:

sudo apt upgrade

Enter the interactive input letter above Y You can start the upgrade.

You can combine the following two commands to upgrade with one click:

sudo apt update && sudo apt upgrade -y

Install the mplayer package:

sudo apt install mplayer

If you don't remember the complete package name, you can enter only the first part of the package name, then press the Tab key, and it will list related package names:

In the above example, we input to redsPress the Tab key, and four related packages will be output.

If we want to install a software package but do not want to upgrade it if it already exists, we can use –no-upgrade option:

sudo apt install <package_name> --no-upgrade

Install mplayer if it exists, do not upgrade:

sudo apt install mplayer --no-upgrade

If you only want to upgrade and not install, you can use --only-upgrade parameter:

sudo apt install <package_name> --only-upgrade

Upgrade mplayer only, do not install it if it does not exist:

sudo apt install mplayer --only-upgrade

If you need to set a specific version, the syntax format is as follows:

sudo apt install <package_name>=<version_number>

package_name For package name,version_number For version number.

You can remove packages using the remove command:

sudo apt remove mplayer

Search for related packages named libimobile:

apt search libimobile

View the relevant information of the pinta package:

apt show pinta

List the software packages that can be updated:

apt list --upgradeable

Clean up the dependencies and library files that are no longer used:

sudo apt autoremove

Enter the interactive input letter above Y Start cleaning up.