All about the debian package managers: dpkg, apt and aptitude explained

All about the debian package managers: dpkg, apt and aptitude explained
This tutorial explains how to install, remove, search and list packages using dpkg, apt and aptitude package managers for Linux Debian with a brief description of each command.

  • dpkg
  • Installing software using dpkg
  • Removing software using dpkg in Debian
  • List programs using dpkg in Debian
  • List files belonging to a program using dpkg
  • Show installation directories using dpkg
  • apt
  • apt repositories
  • Install software using apt
  • Remove software using apt
  • Searching packages using apt
  • Listing packages using apt
  • apt troubleshooting
  • aptitude
  • Installing software with aptitude
  • Updating repositories using aptitude
  • Removing software with aptitude
  • Upgrading software using aptitude
  • Related articles on LinuxHint

DPKG

dpkg  is the Linux Debian packages manager. When apt or apt-get are used they invoke the dpkg program to install or remove applications while including additional functions dpkg doesn’t like dependencies resolution. The program dpkg can be used to install or remove programs, list them or specific information on them.

Note: To show examples the package net-tools will be used, you use any .deb package, to use the net-tools package on the terminal run:

wget http://ftp.us.debian.org/debian/pool/main/n/net-tools/
net-tools_1.60+git20161116.90da8a0-1_amd64.deb

Installing software using dpkg Debian:

To install packages use the parameter -i (install):

dpkg -i <PackageName.deb>

Note: replace <PackageName> for your .deb package.

Removing software using dpkg in Debian:

The remove packages the parameter –remove is needed as in the example below:

dpkg –remove <PackageName.deb>

List programs using dpkg in Debian:

To print a list of installed packages use the parameter -l (list):

dpkg -l

 

Search packages or files belonging to programs  using dpkg in Debian:

The -s (search) parameter is useful to search specific packages but this command will also display software metadata.

 

List files belonging to a program using dpkg:

With the dpkg command you can list all files associated or belonging to an installed package by using the -L parameter:

dpkg -L <PackageName>

Show installation directories using dpkg:

Before installing a new package we can know it’s installation directories by using the -c parameter:

dpkg -c <Package Name>

APT/APT-GET

 

The command apt is advantageous over dpkg because it resolves dependencies and downloads updated software automatically. To download software this command points to a series of software repositories located in the file /etc/apt/sources.list. Initially after installing Debian we need to edit this file commenting the line pointing to Debian DVD/USB installation path and adding the proper repositories.
The apt command uses the dpkg program to manage packages.

apt repositories

You can edit the sources.list file using nano and you can read it by running:

less /etc/apt/sources.list

In my case for Debian Stretch the file /etc/apt/sources.list should have all lines commented except for lines:

deb http://deb.debian.org/debian stretch main
deb-src http://deb.debian.org/debian stretch main
 
deb http://deb.debian.org/debian-security/ stretch/updates main
deb-src http://deb.debian.org/debian-security/ stretch/updates main

 

deb http://deb.debian.org/debian stretch-updates main
deb-src http://deb.debian.org/debian stretch-updates main

When updating the  apt as I show later in this tutorial, all repositories on the sources.list and under the /etc/apt/ directory will be included, you add add new files with additional repositories instead of editing the sources.list file.

Install software using apt:

Installing software using apt requires the option install previous to the program’s name. To try apt install the package manager aptitude used in future instructions.

apt install <PackageName>

Note: you can add the option -y to avoid being asked for confirmation when installing programs.

Removing software using apt:

To remove packages with the apt command run:

apt remove <PackageName>

Note: also when removing software you can use the option -y to avoid being asked for confirmation.

Search packages using apt:

Using the option search you can look for specific packages, in the following image nikto is search, to search a package type:

apt search <PackageName>

Listing packages using apt:

You can list installed packages by executing:

apt list

apt troubleshooting

Sometimes due to bad software removal or similar issues apt may fail, it has some commands to fix common apt package manager problems.

apt-get clean
apt-get autoclean
apt-get -f install
apt-get –fix-missing install
apt-get –purge autoremove
apt update


aptitude

The aptitude packages managers works similarly to apt. It also allows to download and install software and has an interactive mode within the terminal. This package manager has an interactive mode which allows to see and browse packages by status, install and remove packages. It can also be used from the command line with similar options to the apt package manager, aptitude uses the same repositories apt does. To see the interactive mode just call the program running the command aptitude without additional options in the console.

To quit the interactive mode, just press Q and confirm pressing Y.

Updating aptitude:

To update your repositories using aptitude you can run:

aptitude update

Install packages using aptitude:

Similarly to apt, to install software using aptitude you can run:

aptitude install <PackageName>

Remove packages using aptitude:

Search packages using aptitude:

 To search packages with aptitude we can use commands or the interactive console running “aptitude” without options as mentioned before. To search packages from the command line run:

List packages using aptitude:

Aptitude can also be used to list programs in the following way:

aptitude search ~i

Upgrading with aptitude: 

To upgrade software using aptitude run:

aptitude safe-upgrade

Just as with apt, when using aptitude you can add the -y option to prevent being asked for installation removal or upgrade confirmation.

That’s basically what you need to know to manage packages on Debian, if you have any inquiry on Linux in general contact us through our support channel at https://support.linuxhint.com or through twitter @linuxhint.

Related articles:

List all installed packages on Debian
Uninstall Ubuntu and Debian packages with apt-get and dpkg

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *