Apt Package Management Tool

apt (Advanced Package Tool) is a command line package manager that provides commands for searching, managing and querying package information. apt is a more modern user friendly package manager that can be used in place of the older "apt-get" and "apt-cache" package management tools. The most useful commands have been grouped into apt to simplify the process of package management.

Below are a list of the commands now included within the "apt" package management tool:

Most used commands:
list - list packages based on package names
search - search in package descriptions
show - show package details
install - install packages
reinstall - reinstall packages
remove - remove packages
autoremove - Remove all unused packages automatically
update - update list of available packages
upgrade - upgrade the system by installing/upgrading packages
full-upgrade - upgrade the system by removing/installing/upgrading packages
edit-sources - edit the source information file
satisfy - satisfy dependency strings

apt command examples

Below are some examples of commonly used "apt commands. Note:The majority of "apt" commands will need to be run as the "root" user or with escalated privileges using "sudo".

Update Package Information

Before installing any packages, it is always a good idea to run the "apt update" command to update your package information.

Command issued: sudo apt update


$ sudo apt update
Hit:1 http://gb.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://gb.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Get:4 http://gb.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Fetched 324 kB in 0s (723 kB/s)   
Reading package lists... Done
Building dependency tree       
Reading state information... Done
82 packages can be upgraded. Run 'apt list --upgradable' to see them.

Display packages that can be upgraded

To produce a list of any packages on your system that can be upgraded, you can issue the following command.

Command issued: sudo list --upgradable


$ sudo apt list --upgradable
Listing... Done
alsa-ucm-conf/focal-updates,focal-updates 1.2.2-1ubuntu0.7 all [upgradable from: 1.2.2-1ubuntu0.5]
alsa-utils/focal-updates 1.2.2-1ubuntu2.1 amd64 [upgradable from: 1.2.2-1ubuntu2]
apport-gtk/focal-updates,focal-updates 2.20.11-0ubuntu27.17 all [upgradable from: 2.20.11-0ubuntu27.16]
apport/focal-updates,focal-updates 2.20.11-0ubuntu27.17 all [upgradable from: 2.20.11-0ubuntu27.16]
apt-utils/focal-updates 2.0.5 amd64 [upgradable from: 2.0.4]
apt/focal-updates 2.0.5 amd64 [upgradable from: 2.0.4]
fonts-opensymbol/focal-updates,focal-updates 2:102.11+LibO6.4.7-0ubuntu0.20.04.1 all [upgradable from: 2:102.11+LibO6.4.6-0ubuntu0.20.04.1]
gjs/focal-updates 1.64.5-0ubuntu0.20.04.01 amd64 [upgradable from: 1.64.3-1~ubuntu20.04.1]
gnome-shell-extension-appindicator/focal-updates,focal-updates 33.1-0ubuntu0.20.04.2 all [upgradable from: 33.1-0ubuntu0.20.04.1]
grub-common/focal-updates 2.04-1ubuntu26.11 amd64 [upgradable from: 2.04-1ubuntu26.9]
grub-pc-bin/focal-updates 2.04-1ubuntu26.11 amd64 [upgradable from: 2.04-1ubuntu26.9]
grub-pc/focal-updates 2.04-1ubuntu26.11 amd64 [upgradable from: 2.04-1ubuntu26.9]

Note: the above is only a sample of the packages listed. Your output on your system will probably be different depending on the OS version and packages installed.

Display installed packages

The "apt list --installed" command can be used to show what packages are installed on your system.

To display specific information about a single package, you can specify a package name "apt list --installed packagename.


$ sudo apt list --installed htop
Listing... Done
htop/focal,now 2.2.0-2build1 amd64 [installed]

Update packages and security updates

The upgrade option is used to install available upgrades of all packages currently installed on your system. New packages will be installed if required to satisfy dependencies, but existing packages will never be removed. If an upgrade for a package requires the removal of an installed package the upgrade for this package isn't performed.

Command issued: sudo apt upgrade


$ sudo apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  chromium-codecs-ffmpeg-extra fonts-font-awesome fonts-glyphicons-halflings gstreamer1.0-vaapi javascript-common libatomic1 libdbi1
  libgstreamer-plugins-bad1.0-0 libhiredis0.14 libjemalloc2 libjs-bootstrap libjs-d3 libjs-jquery libjs-jquery-form libjs-jquery-metadata
  libjs-jquery-tablesorter libjs-jquery-ui libjs-rickshaw liblua5.1-0 libndpi2.6 libnl-3-200:i386 libnl-genl-3-200:i386 librrd8
  libva-wayland2 libwireshark-data lua-bitop lua-cjson node-html5shiv ntopng-data redis-server redis-tools
Use 'sudo apt autoremove' to remove them.
The following packages will be upgraded:
  alsa-ucm-conf alsa-utils apport apport-gtk apt apt-utils fonts-opensymbol gjs gnome-shell-extension-appindicator grub-common grub-pc
  grub-pc-bin grub2-common iio-sensor-proxy libapt-pkg6.0 libasound2 libasound2-data libatopology2 libgjs0g libjuh-java libjurt-java
  libldap-2.4-2 libldap-common libnss-systemd libpam-systemd libpci3 libprocps8 libreoffice-base-core libreoffice-calc libreoffice-common
  libreoffice-core libreoffice-draw libreoffice-gnome libreoffice-gtk3 libreoffice-help-common libreoffice-help-en-gb libreoffice-help-en-us
  libreoffice-impress libreoffice-l10n-en-gb libreoffice-math libreoffice-ogltrans libreoffice-pdfimport libreoffice-style-breeze
  libreoffice-style-colibre libreoffice-style-elementary libreoffice-style-tango libreoffice-writer libridl-java libseccomp2 libsystemd0
  libudev1 libuno-cppu3 libuno-cppuhelpergcc3-3 libuno-purpenvhelpergcc3-3 libuno-sal3 libuno-salhelpergcc3-3 libunoloader-java libwacom-bin
  libwacom-common libwacom2 libxmlb1 linux-firmware pciutils procps python3-apport python3-distupgrade python3-problem-report python3-uno
  python3-update-manager systemd systemd-sysv systemd-timesyncd thermald ubuntu-release-upgrader-core ubuntu-release-upgrader-gtk udev
  uno-libs-private update-manager update-manager-core update-notifier update-notifier-common ure
82 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
Need to get 217 MB of archives.
After this operation, 1,027 kB of additional disk space will be used.
Do you want to continue? [Y/n] 

Full system upgrade

To perform a full system upgrade, the following command is used: "sudo apt full-upgrade". The "full-upgrade" command performs the same function of the "upgrade command, however, it will remove currently installed packages if needed to upgrade the system.

Command issued: sudo apt full-upgrade


$ sudo apt full-upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  chromium-codecs-ffmpeg-extra fonts-font-awesome fonts-glyphicons-halflings gstreamer1.0-vaapi javascript-common libatomic1 libdbi1
  libgstreamer-plugins-bad1.0-0 libhiredis0.14 libjemalloc2 libjs-bootstrap libjs-d3 libjs-jquery libjs-jquery-form libjs-jquery-metadata
  libjs-jquery-tablesorter libjs-jquery-ui libjs-rickshaw liblua5.1-0 libndpi2.6 libnl-3-200:i386 libnl-genl-3-200:i386 librrd8
  libva-wayland2 libwireshark-data lua-bitop lua-cjson node-html5shiv ntopng-data redis-server redis-tools
Use 'sudo apt autoremove' to remove them.
The following packages will be upgraded:
  alsa-ucm-conf alsa-utils apport apport-gtk apt apt-utils fonts-opensymbol gjs gnome-shell-extension-appindicator grub-common grub-pc
  grub-pc-bin grub2-common iio-sensor-proxy libapt-pkg6.0 libasound2 libasound2-data libatopology2 libgjs0g libjuh-java libjurt-java
  libldap-2.4-2 libldap-common libnss-systemd libpam-systemd libpci3 libprocps8 libreoffice-base-core libreoffice-calc libreoffice-common
  libreoffice-core libreoffice-draw libreoffice-gnome libreoffice-gtk3 libreoffice-help-common libreoffice-help-en-gb libreoffice-help-en-us
  libreoffice-impress libreoffice-l10n-en-gb libreoffice-math libreoffice-ogltrans libreoffice-pdfimport libreoffice-style-breeze
  libreoffice-style-colibre libreoffice-style-elementary libreoffice-style-tango libreoffice-writer libridl-java libseccomp2 libsystemd0
  libudev1 libuno-cppu3 libuno-cppuhelpergcc3-3 libuno-purpenvhelpergcc3-3 libuno-sal3 libuno-salhelpergcc3-3 libunoloader-java libwacom-bin
  libwacom-common libwacom2 libxmlb1 linux-firmware pciutils procps python3-apport python3-distupgrade python3-problem-report python3-uno
  python3-update-manager systemd systemd-sysv systemd-timesyncd thermald ubuntu-release-upgrader-core ubuntu-release-upgrader-gtk udev
  uno-libs-private update-manager update-manager-core update-notifier update-notifier-common ure
82 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
Need to get 217 MB of archives.
After this operation, 1,027 kB of additional disk space will be used.
Do you want to continue? [Y/n] 

Install a package

To install a package using "apt", issue the command "sudo apt install packagename". The package name to install is passed after the install parameter.

Below is an example of installing the "htop" package

Command issued: sudo apt install htop


$ sudo apt install htop
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed
  htop
0 to upgrade, 1 to newly install, 0 to remove and 82 not to upgrade.
Need to get 80.5 kB of archives.
After this operation, 225 kB of additional disk space will be used.
Get:1 http://gb.archive.ubuntu.com/ubuntu focal/main amd64 htop amd64 2.2.0-2build1 [80.5 kB]
Fetched 80.5 kB in 0s (640 kB/s)
Selecting previously unselected package htop.
(Reading database ... 191781 files and directories currently installed.)
Preparing to unpack .../htop_2.2.0-2build1_amd64.deb ...
Unpacking htop (2.2.0-2build1) ...
Setting up htop (2.2.0-2build1) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...

Remove a package

To remove a package using "apt", issue the command "sudo apt remove packagename". The package name is passed after the install parameter.

To remove a package and its configuration files, we have to use a different parameter "purge". Example: "sudo apt purge packagename

Below is an example of removing the package "htop".

Command issued: sudo apt remove htop


$ sudo apt remove htop
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED
  htop
0 to upgrade, 0 to newly install, 1 to remove and 82 not to upgrade.
After this operation, 225 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 191790 files and directories currently installed.)
Removing htop (2.2.0-2build1) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...

Autoremove packages

Overtime, many packages get installed and uninstalled, this often leaves packages that are no longer in use or needed. These packages can be removed with an option called "autoremove".

You may come across a message indicating the following: "The following packages were automatically installed and are no longer required".

Note: You should check that the list does not include applications you have grown to like even though they were once installed just as a dependency of another package. You can mark such a package as manually installed by using apt-mark.

Below is an example from an Ubuntu system. The packages will be different on your system.

Command issued: sudo apt autoremove


$ sudo apt autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED
  chromium-codecs-ffmpeg-extra fonts-font-awesome fonts-glyphicons-halflings gstreamer1.0-vaapi javascript-common libatomic1 libdbi1
  libgstreamer-plugins-bad1.0-0 libhiredis0.14 libjemalloc2 libjs-bootstrap libjs-d3 libjs-jquery libjs-jquery-form libjs-jquery-metadata
  libjs-jquery-tablesorter libjs-jquery-ui libjs-rickshaw liblua5.1-0 libndpi2.6 libnl-3-200:i386 libnl-genl-3-200:i386 librrd8
  libva-wayland2 libwireshark-data lua-bitop lua-cjson node-html5shiv ntopng-data redis-server redis-tools
0 to upgrade, 0 to newly install, 31 to remove and 82 not to upgrade.
After this operation, 32.9 MB disk space will be freed.
Do you want to continue? [Y/n] 

Searching for Packages

apt is now able to search for packages like the older utility "apt-cache". To search for a package, issue the command: "sudo apt search packagename.

Below is an example of a search command being issued looking for information on htop. Notice we are specifying to look for packages that start "htop*"

Command issued: sudo apt search ^htop


$ sudo apt search ^htop
Sorting... Done
Full Text Search... Done
htop/focal 2.2.0-2build1 amd64
  interactive processes viewer

Package Information

To show information about a package, you can use the command: "sudo apt show packagename"

Command issued: sudo apt show htop


$ sudo apt show htop
Package: htop
Version: 2.2.0-2build1
Priority: optional
Section: utils
Origin: Ubuntu
Maintainer: Ubuntu Developers 
Original-Maintainer: Daniel Lange 
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 225 kB
Depends: libc6 (>= 2.15), libncursesw6 (>= 6), libtinfo6 (>= 6)
Suggests: lsof, strace
Homepage: https://hisham.hm/htop/
Task: server, cloud-image, lubuntu-desktop
Download-Size: 80.5 kB
APT-Sources: http://gb.archive.ubuntu.com/ubuntu focal/main amd64 Packages
Description: interactive processes viewer
 Htop is an ncursed-based process viewer similar to top, but it allows one
 to scroll the list vertically and horizontally to see all processes and
 their full command lines.
 .
 Tasks related to processes (killing, renicing) can be done without
 entering their PIDs.

Show package dependencies

To list package dependencies, you can use the command: "sudo apt depends packagename"

In the example below, we are looking for dependencies that relate to the package "htop"

Command issued: sudo apt depends htop


$ sudo apt depends htop
htop
  Depends: libc6 (>= 2.15)
  Depends: libncursesw6 (>= 6)
  Depends: libtinfo6 (>= 6)
  Suggests: lsof
  Suggests: strace