Managing Software Packages on Linux
13 min read·Jan 1, 2025
The Advanced Package Tool (APT) is a free collection of pre-installed tools that simplify the process of installing, upgrading, configuring, and removing software packages on Linux distributions.
APT relies on package repositories, which are collections of software packages maintained by the distribution's community or organization, located on remote servers.
Searching for packages
To search for a software package on the APT registries that partially matches a specified keyword, you can use the apt search command:
$ apt search term
Where term is a regular expression such as tree or tree$.
On the other hand, to perform an exact search, you can use the following syntax:
$ apt search '^term$'
Which in regex translates to: "the package name starts and ends with the specified term".
Upon execution, the apt command will perform a linear, lexically-ordered search through the available packages in APT repositories and output the name and short description of each package matching the specified regex.
Example
This command will output all the packages containing the term tree in their name:
$ apt search tree
Sorting... Done
Full Text Search... Done
tre-command/jammy 0.3.6-2 amd64
Tree command, improved
tree/jammy 2.0.2-1 amd64
displays an indented directory tree, in color
tree-ppuzzle/jammy 5.3~rc16+dfsg-9 amd64
Parallelized reconstruction of phylogenetic trees by maximum likelihood
tree-puzzle/jammy 5.3~rc16+dfsg-9 amd64
Reconstruction of phylogenetic trees by maximum likelihood
tree-puzzle-doc/jammy 5.3~rc16+dfsg-9 all
Reconstruction of phylogenetic trees by maximum likelihood (doc)
treeline/jammy 3.1.4-1 all
versatile tree-like structured custom data manager
This command will only output the package whose exact name is tree:
$ apt search '^tree$'
Sorting... Done
Full Text Search... Done
tree/jammy 2.0.2-1 amd64
displays an indented directory tree, in color
Showing package information
To get additional information about a package, such as its latest available version number, maintainer list, size, dependency list, and more, you can use the apt show command:
$ apt show package
Where package is the exact name of the package.
Example
This command will output detailed information about the tree package:
$ apt show tree
Package: tree
Version: 2.0.2-1
Priority: optional
Section: universe/utils
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Florian Ernst <florian@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 116 kB
Depends: libc6 (>= 2.34)
Homepage: http://mama.indstate.edu/users/ice/tree/
Task: xubuntu-desktop, lubuntu-desktop, ubuntu-mate-core, ubuntu-mate-desktop, ubuntu-budgie-desktop, ubuntu-budgie-desktop-raspi
Download-Size: 47.9 kB
APT-Sources: http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
Description: displays an indented directory tree, in color
Installing packages
To install one or more packages, including any additional packages they depend on in order to function properly, you can use the apt install command:
$ sudo apt install package ...
Where package ... is a list of package names separated by a space character.
Notes:
This command requires
sudoprivileges to run, as regular users don't have permission to install system-wide packages.Before installing packages, make sure to update the index with the latest packages information using the
sudo apt updatecommand.
Example
This command will first update the index:
$ sudo apt update
Get:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [129 kB]
Hit:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [128 kB]
Hit:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Get:5 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [2602 kB]
Get:6 http://archive.ubuntu.com/ubuntu jammy-updates/universe amd64 Packages [1448 kB]
Fetched 4307 kB in 1s (7798 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
This command will install the latest available version of the tree package:
$ sudo apt install tree
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
tree
0 upgraded, 1 newly installed, 0 to remove and 28 not upgraded.
Need to get 47.9 kB of archives.
After this operation, 116 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/universe amd64 tree amd64 2.0.2-1 [47.9 kB]
Fetched 47.9 kB in 0s (738 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package tree.
(Reading database ... 14364 files and directories currently installed.)
Preparing to unpack .../tree_2.0.2-1_amd64.deb ...
Unpacking tree (2.0.2-1) ...
Setting up tree (2.0.2-1) ...
Processing triggers for man-db (2.10.2-1) ...
Installing a specific package version
To check the available versions of a package, you can use the apt list command:
$ apt list -a package
To install a specific package version instead of the latest default version, you can use the apt install command with the following syntax:
$ sudo apt install package=version ...
Where:
packageis the name of the package.versionis the version number of the package.
Example
This command will output the list of available versions of the mysql-client package:
$ apt list -a mysql-client
Listing... Done
mysql-client/jammy-updates,jammy-security 8.0.39-0ubuntu0.22.04.1 all
mysql-client/jammy 8.0.28-0ubuntu4 all
This command will install the mysql-client package at version 8.0.28-0ubuntu4:
$ sudo apt install mysql-client=8.0.28-0ubuntu4
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
mysql-client
0 upgraded, 1 newly installed, 0 to remove and 27 not upgraded.
Need to get 9414 B of archives.
After this operation, 111 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 mysql-client all 8.0.28-0ubuntu4 [9414 B]
Fetched 9414 B in 0s (31.3 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package mysql-client.
(Reading database ... 14360 files and directories currently installed.)
Preparing to unpack .../mysql-client_8.0.28-0ubuntu4_all.deb ...
Unpacking mysql-client (8.0.28-0ubuntu4) ...
Setting up mysql-client (8.0.28-0ubuntu4) ...
Upgrading packages
To upgrade a package to a greater or latest version, you can use the apt install command:
$ sudo apt install package[=version] ...
Alternatively, you can use the apt upgrade command to upgrade all installed packages to their latest version at once:
$ sudo apt upgrade
Notes:
- Before upgrading packages, make sure to update the index with the latest packages information using the
sudo apt updatecommand.- This command will also upgrade the package dependencies to their latest version.
Uninstalling packages
To uninstall packages, you can use the apt remove command:
$ sudo apt remove package ...
Alternatively, to uninstall packages including their dependencies, you can use the apt purge command:
$ sudo apt purge package ...
Example
This command will remove the tree package:
$ apt remove tree
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
tree
0 upgraded, 0 newly installed, 1 to remove and 28 not upgraded.
After this operation, 116 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 14372 files and directories currently installed.)
Removing tree (2.0.2-1) ...
Processing triggers for man-db (2.10.2-1) ...
Note: When prompted with the question "Do you want to continue? [Y/n]", type
yand pressENTERto confirm the package deletion.
Removing unused dependencies
To remove all dependencies that are no longer required by any package on the system, you can use the apt autoremove command:
$ sudo apt autoremove
Summary
Here's a summary of what you've learned in this lesson:
- The
apt searchcommand is used to search for available packages on the APT repositories. - The
apt showcommand is used to retrieve information about a package. - The
apt installcommand is used to install packages on the system. - The
apt list -acommand is used to list all available versions of a package. - The
apt updatecommand is used to update the APT index. - The
apt upgradecommand is used to upgrade packages to a greater version (if available). - The
apt removecommand is used to uninstall packages from the system. - The
apt purgecommand is used to uninstall packages and their dependencies from the system. - The
apt autoremovecommand is used to uninstall unused dependencies from the system.
Enjoying the courses?
I've made these courses completely free so anyone can learn from them. If they've helped you and you'd like to actively support the work behind BackendBrewery, you can leave a tip:
Support BackendBrewery