dpkg
There are two main package systems on Debian - dpkg and apt (advanced package tool)
To install a Debian package use:
dpkg -i <package_name>.deb
To remove a package use:
dpkg -r <package_name>.deb
To completely remove everything use:
dpkg -P <package_name>.deb
To get information about the package use:
dpkg -I <package_name>.deb
To list all installed packages on the system use:
dpkg --get-selections
To get a list of every file installed by a specific package use:
dpkg -L <package_name>
To find out which package owns a specific file use:
dpkg-query -S <filename>
To reconfigure installed package run:
dpkg-reconfigure <package_name>
apt
APT (Advanced Package Tool) - acts like a "frontend" for dpkg. It extends the functionality of dpkg system.
APT uses repositories to install packages. These repositories can be local, remote or CD-ROM based.
The main utilities that interact with APT:
apt-get - used to download, install, upgrade or remove packages from the system.
apt-cache - used to perform operations, like searches, in the package index.
apt-file - used for searching for files inside packages.
There is also another utility named as "apt". This utilitiy is simpler and its commands are interchangeable with apt-get
To update package index information use:
apt-get update
apt update
After updating the index, you can install the package with:
apt-get install <package_name>
To remove package use:
apt-get remove <package_name>
Be aware: apt automatically solves dependency resolution during installation or removal of the package. This means that apt will automatically download or remove dependencies on your system.
To remove the package and corresponding any configuration files use:
apt-get purge <package_name>
apt-get remove --purge <package_name>
To fix broken dependencies use:
apt-get install -f
apt install -f
To automatically upgrade any installed packages to the latest versions available use:
apt-get update
apt-get upgrade
apt update
apt upgrade
To upgrade a single package use:
apt-get upgrade <package_name>
Local cache
During installation or package update, the corresponding .deb
packages are downloaded to /var/cache/apt/archives
or /var/cache/apt/archives/partial/
. These directories represent local cache.
To clean cache and reclaim space use:
apt clean
Searching for packages
To search for a package in the package index use:
apt-cache search <package_name>
To get full package description use:
apt-cache show <package_name>
You can also use regular expressions to make your search more precise.
The sources list
APT uses a list of sources to know where to get packages from. This list is stored in the file sources.list
, located inside the /etc/apt
directory. This file can be edited directly with a text editor.
To add a new repository to get packages from, you can simply add the corresponding line (usually provided by the repository maintainer) to the end of sources.list
, save the file and reload the package index with apt-get update
. After that, the packages in the new repository will be available for installation using apt-get install
.
Inside the /etc/apt/sources.list.d
directory you can add files with additional repositories to be used by APT, without the need to modify the main /etc/apt/sources.list
file. These are simple text files, with the same syntax as for /etc/apt/sources.list
and saved with the .list
file extension.
Listing package contents and finding files
There also additional apt-file
utility that can be used to list package contens, find files and etc.
To install the tool use:
apt-get install apt-file
To update package index use:
apt-file update
To list the contents of a package use:
apt-file list <package_name>
To know which package provides a specific file use:
apt-file search <filename>
This utility also searches through uninstalled packages.