APT" stands for "Advanced Package Tool." APT is a package management system used by Debian and its derivatives, such as Ubuntu, to handle the installation, upgrade, and removal of software packages. It simplifies the process of managing software on Unix-like operating systems by automatically resolving dependencies, retrieving packages from repositories, and configuring the packages.
APT was designed to work with Debian's .deb packages, and it uses repositories where packages are stored, allowing users to search, install, or remove software easily. APT also has a command-line interface (apt-get, apt-cache) and other front-end tools like Synaptic Package Manager, which provides a graphical user interface for package management.
What does APT do?
APT is a set of core tools found inside the Debian operating system. It provides utilities for the installation and removal of software packages and dependencies on a system.
- APT is a powerful tool that can be used to manage software packages on Debian-based systems.
- APT can be used to install, remove, upgrade, and downgrade software packages.
- APT can also be used to manage dependencies between packages.
- APT is a valuable tool for any system administrator who needs to manage software packages on a Debian-based system.
apt-get / high level package handling utility
apt-get
is the command-line tool for handling packages and provides functions such as installing, removing, and updating packages on a system with a single operation. We’ll cover the following commands for apt-get
:
install
and--reinstall
remove
purge
or--purge
upgrade
update
clean
andautoclean
apt-cache / high level package query utlity
apt-cache
provides an interface to perform read-only operations on the APT package cache. apt-cache
does not change the state of the system, but allows the user to extract useful information from package metadata.
We’ll go over the following commands for apt-cache
:
pkgnames
search
show
dpkg / low level package manager for Debian
dpkg
is a tool for installing, removing, and querying individual packages. We’ll investigate some common commands and go over some basic usage of dpkg
in a couple of real-world examples.
--list
or-l
--install
--remove
--purge
--update
--contents
apt-get
high level package handling utility
Installing a Debian package:
apt-get
wants you to pass the [package-name]
you wish to install, for example:
Removing a Debian package:
The following will remove a package without removing its configuration files:
To remove a package and its configuration files, use purge
:
or alternatively, use the --purge
flag on the remove command:
Update package index files from sources.list:
When this command is run, all available packages are fetched and re-indexed from the locations specified in /etc/apt/sources.list
and /etc/apt/sources.list.d/
.
Upgrade all Debian system packages:
This command installs all of the latest versions of each package installed on the system and is, generally, not recommended to be run on production systems.
Update / Reinstall a single package:
Once you’ve run apt-get update
to update repository metadata, you can update an installed package by running apt-get install
If you need to force reinstall a package, just pass the --reinstall
flag
By passing the --reinstall
flag, you will effectively force the package to be reinstalled even if it’s already installed and at the latest version. This will completely remove the package from the system* and reinstall it.
*Packages that depend on the [package-name]
being reinstalled will not be removed from the system
APT cache files:
APTs cached files are located in:
/var/cache/apt/archives/
Clear the APT cache:
The clean
command clears out the local repository of downloaded package files. It removes everything except the partials folder and lock file from /var/cache/apt/archives/
.
Use apt-get clean
to free up disk space when necessary, or as part of regularly scheduled maintenance.
Remove useless files from the APT cache:
autoclean
is another method used to clear out the local repository of downloaded package files, just like clean
. The difference between clean
and autoclean
is that the latter only removes package files that can no longer be downloaded from their sources, and are very likely to be useless.
apt-cache
high level package query utility
List all available packages:
This command will output a list of available package names for your system:
Searching for a specific Debian package:
This is really useful in case you don’t know the exact [package-name]
, but rather a description of what that package does; for example “Network Security”:
This will return a list of packages containing the string “Network Security” in the package description. Using apt-cache will look in the name
, description
, and provides
fields of the available packages by default.
Show Debian package information:
This will show apt metadata for the [package-name]
given. This is an example using the “screen” package:
will output:
NOTE: Installed-Size and Size are returned in bytes - link to discussion
dpkg
low level package manager for Debian
Install a package:
or alternatively, use the --install
flag
Remove a package:
To remove a package using dpkg
without removing its configuration files:
alternatively, use the -r
flag:
To remove a package using dpkg
along with its corresponding configuration files, use the --purge
command:
List available system packages:
dpkg -l
allows you to list a set of packages on the system and the state of those packages:
You can use a regular expression to list information about all matching package names. For example:
will return all packages starting with the letters “re”:
The first column shows the state of the package. You can learn more about package states by reading the dpkg man page: man 1 dpkg
.
If the [package-name-pattern]
is omitted from dpkg -l
then all packages in /var/lib/dpkg/status
will be listed, excluding packages that have been marked not-installed
will output something like:
List files in a package:
dpkg maintains a list of packages that are installed on a system in /var/lib/dpkg
.
You can query the files in an installed package using dpkg -L
:
So, for example:
returns the following results:
If you’d like to list the files in a debian package that you’ve downloaded (but not installed), you can use the --contents
flag.
For example:
returns the following results:
When the --contents
flag is used, dpkg
calls down to an action provided by another tool dpkg-deb
, which provides tools to manipulate a debian package archive.
Show packages containing a filename or filepath:
For example, passing a specific filepath:
will return all the package names that contain that file path.
Show package information:
You can show package metadata of installed packages by using dpkg -s
:
for example, the following command:
returns the package metadata:
Additional APT tools
Here are some additional tips for using APT and its related tools:
-
Use the
apt-cache show
command to view information about a package, such as its version, description, and dependencies. -
Use the
apt-cache search
command to search for packages by name or keyword. -
Use the
apt-get install
command to install a package. -
Use the
apt-get remove
command to remove a package. -
Use the
apt-get update
command to update the list of available packages. -
Use the
apt-get upgrade
command to upgrade all installed packages to the latest version. -
Use the
apt-get dist-upgrade
command to upgrade all installed packages, including removing and installing packages as needed. -
Use the
apt-get autoremove
command to remove packages that are no longer needed. -
Use the
apt-get clean
command to remove downloaded package files. -
Use the
apt-get autoclean
command to remove downloaded package files that are no longer needed.
Conclusion
Getting more familiar with your package manager’s tools can help you be more productive when finding, installing, and querying packages.apt-get
, apt-cache
, and dpkg
.
You can learn more about the tools mentioned in this blog post by reading the man pages as well.