The Debian package management offers several tools including, dpkg, Advanced Packaging Tool (APT), and aptitude utility to perform package management tasks. This tutorial uses each of these Debian Management tools to describe:
- How to install, remove, reinstall, and upgrade Debian packages?
- How to find files or libraries of uninstalled packages?
- How to obtain package metadata or version and content details when the package is uninstalled?
Background
In the earliest Linux systems, packages were installed or added by grabbing the source code from the project built it. The users then compiled the source code into runnable binaries, including manual pages, libraries, and configuration files to create a required program. The user may find the programs already compiled by someone to add to the system in a better scenario.
The compiled program was the tarball: a single file containing multiple files gathered for convenient distribution. In other words, after installation from a tarball, files spread across the Linux system in various appropriate folders and subdirectories such as /etc., /bin, /var, /usr/share/man, etc.
Even though it’s easy to create a tarball, it has some issues such as:
- Tracking down required dependencies
- The user is not aware of configuration files and documentation located in the system. It further complicates the process of software removal.
- Tarballs do not contain software metadata, making it difficult to fix bugs and update to a new version.
To resolve these problems, Linux introduced a complex system for package management dividing all the Linux distributions into incorporating one of the two major packaging formats known as DEB and RPM. The article focuses on the Debian-based-package management system used by Debian and derivatives of Debian distribution such as Ubuntu, Linux Mint, etc.
Before moving onwards with the demonstration of various package management tasks, let’s first explain what the Debian package file is and how all the above discussed Debian package managers differ from each other.
.deb File
A file with a .deb extension contains the content of a Debian package
software. The Deb file further consists of two Tar files that make up the executables, libraries, and other files.
The general syntax of any Debian package file is as follows:
For instance, apache_1.3.31-6_i386.deb tells the base name of software to be apache. 1.3.31-6 is the version number assigned by the packager. Lastly, i386 implies that the package is compiled for Intel x86 architecture.
Besides, any file with the .deb extension is downloadable via the dpkg command and represents a complete file name. At the same time, only the package name apache refers to the first part of the .deb file.
Debian Package Managers
The DPM consists of several layers, as the top layer constitutes commands from the apt family of tools, and the lower layer is of dpkg and associated tools.
dpkg
dpkg is a Debian package manager that installs, removes, and configures packages with the .deb extension. It simply downloads DEB package content to the system and notifies about the required dependencies. But it does not install or configure .deb packages due to missing dependencies as it does not have access to the repositories.
APT
APT is a powerful command-line tool that manages the installation and configuration of deb packages. It further manages and downloads the necessary dependencies to provide the latest software. It works as a front-end for dpkg: after listing all the dependencies and downloading from the repository.
Hence, APT automates the problem in dpkg. It further compares the dependencies and informs the users about the one’s not in use by any package that a user can remove.
Package Location
The package installation from any Debian Software center or command-line utilities (apt/apt-get) happens via downloading packages from one or more repositories. A Debian or APT repository is a server or a local directory containing packages files and their metadata readable by the APT tools.
Hence, on all the Debian-based distributions, the APT Package management system maintains repositories inside the main configuration file /etc/apt/sources.list. So whenever a user executes a command for package installation, the apt/apt-get command looks inside the /etc/apt/sources.list or /etc/apt/sources.list.d for repository URLs.
It then downloads the desired software for installation. The source.list file further contains additional information about the repositories for the software to install. The user can manually add new repositories in the /etc/apt/sources.list.d directory without editing the main configuration file. However, the names of the new repository files must follow the /etc/apt/source.list format. cat the content of the /etc/apt/sources.list file:
The general syntax for each included repository is as follows:
deb-src http://us.archive.ubuntu.com/ubuntu/ saucy-updates universe
- deb: represents the deb archive. It can either be deb that implies .deb package or deb-src repositories containing package source code.
- http: //repo.tld/ubuntu: repository URL
- distro: distribution code name
- component: it’s the repository categories. For instance, the default Ubuntu repositories have four categories: main, restricted, multiverse, and universe.
The APT and other tools use a local database to determine installed packages. To maintain the local database, synchronize the information with the repositories listed in the sources.list using the apt-get update command. Hence, it’s necessary to perform a local database update before each package installation or update.
Aptitude
Aptitude is a menu-driven, text-based interface for dpkg and Advanced Packaging Tool package management functions. It’s best suited for a non-graphical interface environment that makes user tasks easy to perform. It uses apt-get libraries and provides more perks due to an interactive UI.
Debian Package Installation
Linux installation automatically installs a set of packages that a user can further customize as per the use of the system, i.e., desktop, server, or workstation. A user also sometimes requires to install new packages. Let’s discuss package installation concerning the above-discussed package managers.
Installation via APT-GET
Use the apt-get install command to install the package with a list of extra packages. The below screenshot displays the list of dependencies and prompts for continuation.
As shown below, after download the command-line tool also unpacks the libutempter0_1.1.6-3_amd64.deb package.
Unpacking libutempter0:amd64 (1.1.6-3) ...
Instead of installation, the -s flag only figures out if the package depends on other packages.
..<SNIP>...
The following additional packages will be installed:
libutempter0
..<SNIP>...
Installation via dpkg
In case you get to download a .deb file with all the dependencies, without apt-get. Use the following command to install it via dpkg.
Installation via Aptitude
Run aptitude via a terminal with sudo privileges.
Use the Ctrl+T key combination to enter the main aptitude menu. But before that, use the arrow keys to enter the submenu of aptitude ‘Not Installed Packages‘ section. It shows several sub-menus, choose net and scroll down to its submenu to select main to reveal all applications. Choose your desired application and hit Enter to see all the package details.
Mark the application for installation by pressing the ‘+‘ key and hit the ‘g‘ key to begin the installation. During installation, aptitude will be in console mode; once done, it returns to the user interface with a display of a complete package description.
Debian Package Removal
The section elaborates on the Debian package removal process. Let’s discuss the package removal process via each package manager.
Removing Package via APT
The remove option of an apt-get command only removes all the package data.
That is, all the configuration files are left behind. Hence, if the command gets executed accidentally, issue an installation command for the removed package to restore its function. To remove all the configuration files, as well use the purge option.
Besides, the output in the screenshot above depicts that the unrequired dependencies are not removed. For this purpose, the –auto-remove option does the job for us.
Combine the purge and –auto-remove options to completely delete all the data and files along with unrequired dependencies.
Removing Packages via dpkg
The package removal process in dpkg is almost similar. Use dpkg -r to remove the package data and dpkg -P to completely delete the package. First, list the package to ensure if it’s correctly installed in the system.
ubuntu@ubuntu:~$ sudo dpkg -r tmux
ubuntu@ubuntu:~$ sudo dpkg -P tmux
dpkg further allows forcefully deleting the files in a scenario of distribution upgrade that requires the user to delete or remove a package. But sometimes, the remove option doesn’t work due to the package’s unmet dependencies or incomplete installation. For that, dpkg offers forced package removal:
Removing Packages via Aptitude
Uninstallation via aptitude is as simple as the installation. Scroll down and select ‘Installed Packages’ to view all installed programs. Select net->main and choose the program by pressing a ‘–’ key. Press ‘g’ to remove the selected package.
Debian Package Update
To update a single package, use the apt-get command with the install option. It also upgrades the extra packages or dependencies. However, it’s necessary to ensure that the local databases reflect the latest updates:
ubuntu@ubuntu:~$ sudo apt-get install vim
Instead of updating the packages individually, it’s better to update all the applications in the system, as follows:
ubuntu@ubuntu:~$ sudo apt-get upgrade
Finding Uninstalled Debian Package Information
All the package management tools are aware of the available packages a user may need to install. The apt-cache is one such command that maintains a repository containing information about packages from the source list. It enables the user to retrieve the information about the packages in apt’s cache.
For instance, to install a package relevant to a chatting program with no knowledge of the package name, a user can use the following command:
The above command will return a list of packages available for a chat application.
Similarly, a lot of tools are available to find packages from an already available list of packages. Users can find a lot of detail about the installed package with them but not for an uninstalled one, for instance, files inside an uninstalled package. For this purpose, use the -d option with an apt-get command, as it only downloads the package.
The downloaded package file is located inside /var/cache/apt/archives/ directory. Now use the dpkg command with the –info option to display package details or the –contents option to display package files.
ubuntu@ubuntu:~$ dpkg --contents /var/cache/apt/archives/nmap_7.60-1ubuntu5_amd64.deb|less
Finding Installed Debian Packages Information
The dpkg tool makes use of many files available in the /var/lib/dpkg directory. One of them is the /var/lib/dpkg/status file that contains package status information. The use of a dpkg command with the -s option displays the status of the packages on the system.
dpkg also enables Linux users to find details of a particular package and a file belonging to a specific package. The dpkg tool -L option lists all the files and directories of the package of interest. All dpkg requires is a package name, but when multiple versions of an application are available, it requires a more detailed name containing version details.
To find a package containing a specific file, use the -S flag. For instance, use the following command to figure out which package contains the file /usr/bin/apt-get.
Lastly, we can find details or purpose of a particular package as follows:
Conclusion
The article provides a detailed description of Debian’s package management. It discusses various ways to install, remove, update or upgrade packages. We also learned how to find package status and many other details about uninstalled Debian packages. The article is a one-stop guide covering every aspect of package management in Ubuntu or any Debian Distribution. Thank you for coming this far; you can place your queries in the comment section below. For details on package management in RHEL distributions, read Introduction to RPM/YUM package management.