102.4. Use Debian package management

102.4 Use Debian package management

Weight: 3

Description: Candidates should be able to perform package management using the Debian package tools.

Key Knowledge Areas:

  • Install, upgrade and uninstall Debian binary packages

  • Find packages containing specific files or libraries which may or may not be installed

  • Obtain package information like version, content, dependencies, package integrity and installation status (whether or not the package is installed)

Terms and Utilities:

  • /etc/apt/sources.list

  • dpkg

  • dpkg-reconfigure

  • apt-get

  • apt-cache

  • aptitude

What is a package?

A package is a piece of software that provides a piece of the system. Examples of packages:

  • Linux Kernel

  • The C compiler

  • The Firefox web browser

  • The USB library to interact with USB devices

A package contains the files and other instructions needed to make one Software component work on the system.

Packages have dependencies from other packages that must also be downloaded and installed before installing the package with dependencies.

In old days Linux administrators had to deal with dependency hell for installing a package which caused meta package handlers were born.

What is a Package Manager?

The packet manager is the utility that handles the downloading, unpacking and putting the unpacked pieces in the right places.

The general workflow starts with the user requesting a package using the package manager available in the system. The Package manager then finds the requested package from a known location (called software repository) and downloads it. The Package Manager then installs the package and advises on any manual steps that it finds necessary.

Package management tools help System/Server Administrators in many ways such as:

  • Downloading and installing software

  • Compile software from source

  • Keeping track of all software installed, their updates and upgrades

  • Handling dependencies

  • and also keeping other information about installed software and many more

What is a Software Repository?

A Linux repository is a storage location from which our system retrieves and installs OS updates and applications. Each repository is a collection of software hosted on a remote server and intended to be used for installing and updating software packages on Linux systems.

Package Manager consists of two entities:

  • low-level tool

  • high-level too

a low-level tool (such as dpkg or rpm), takes care of the details of unpacking individual packages, running scripts, getting the software installed correctly, while a high-level tool (such as apt-get, yum, or zypper) works with groups of packages, downloads packages from the vendor, and figures out dependencies

The core parts of a linux distro and most of its add-on Software are installed via a Package Management System.

In this course we will talk about package management in Debian based distributions.

dpkg

dpkg is a package manager for Debian-based systems. It can install, remove, and build packages, but unlike other package management systems, it cannot automatically download and install packages or their dependencies.

The dpkg has database and its is located under/var/lib/dpkg directory ;

the "status" file contains the list of installed software on the current system.

Lets take a look at most useful switches:

-l | --list list all packages installed on the system ( --get-selection does the same):

To view a specific package installed or not use the option “-l” along with package-name.

dpkg -i | --install ,install a local .deb file :

And if a package requires any dependencies you would get into trouble:

dpkg does not handle dependencies so and we try to install a package one of two thing will happend:

  • whether It will completely fail !

  • or it will install the package but leave it unconfigured until all dependencies are installed and the apt tool is used to finish the configuration(apt-get install -fwe will see it).

We can also use dpkg --force-dependsto omit dependencies or --force-conflicts to close its eyes to any possible conflicts or --force-reinstallfor reinstalling, but do not forget that any --force command can cause a problem and make the system inconsistent state.

dpkg -L | --listfiles ,To list the files installed by a package:

dpkg -S | --serach ,If we are not sure which package installed a file, dpkg -S may be able to tell us :

note:We can also use dpkg -S string and it would do use regular expression search in the file system to find any matches with the string we have types.

dpkg -s | --status ,Check a Package is installed or not:

dpkg -c | --contents ,will display the contents of a “.deb” package in long-list format:

Do not mess -c with -C, -C checks for partially installed packages.

What is debconf?

When packages are being installed, debconf asks the user questions which determine the contents of the system-wide configuration files associated with that package and stores the user/admin preferences in a database.

Later as the packages are installing, their scripts use the configuration preferences in the database to generate configuration files and otherwise do administrative tasks.This saves the hassle of editing configuration files by hand, and also of waiting for each individual package to install before responding to certain configuration questions.

dpkg-reconfigure

After package installation, it is possible to go back and change the configuration of a package by using the dpkg-reconfigure program (or another program such as Synaptic). For example try:

dpkg -r | --remove , remove a package using its name :

dpkg cares about dependencies by and does not remove them by default,(which is why it doesn't get .deb file, instead it requires package name inorder to explore dependencies), how ever we can force it withdpkg -r --force-depends command but is NOT recommended. It is better to use a package manager that handles dependencies to ensure that the system is in a consistent state.

note:dpkg -P | --purge purge a package! We can also use ‘P‘ option in place of ‘r’ which will remove the package along with configuration file. The ‘r‘ option will only remove the package and not configuration files.

Do not get confused -P with -p , -p will print information about package.

dpkg has lots of options and switches try dpkg --help for more information :

When we work with dpkg we have to have .deb package in hand in order to work with. But how about Package Manager?How package manager like apt find software repositories in Debian based systems?

/etc/apt/sources.list

This file contains information about what repositories [online / remote ] the system will use. This file contains lines in the following format:

deb lines are relative to binary packages, that we can install with apt. deb-src lines are relative to source packages (as downloaded by apt-get source $package) and next compiled. Source packages are needed only if we want to compile some package ourselves, or inspect the source code for a bug. Ordinary users don't need to include such repositories.

The repository components are:

  • Main - Officially supported software.

  • Restricted - Supported software that is not available under a completely free license.

  • Universe - Community maintained software, i.e. not officially supported software.

  • Multiverse - Software that is not free.

Some distributions like Ubuntu also have /etc/apt/sources.list.d directory which provides a way to add sources.list entries in separate .list files.

All .list files are compiled and added to /etc/apt/sources.list file.

APT (Advanced Packaging Tool)

It is a very popular, free, powerful and useful command line package management system that is a front end for dpkg package management system.Initially it was designed for Debian’s.debpackages

Apt is whole command line with no GUI. Whenever invoked from command line along with specifying the name of package to be installed, it finds that package in configured list of sources specified in ‘/etc/apt/sources.list’ along with the list of dependencies for that package and sorts them and automatically installs them along with the current package thus letting user not to worry of installing dependencies.

It is consist of two commands:

  • apt-get

  • apt-cache

What is apt-get?

The apt-get is the command-line tool for working with APT software packages, that is used to work with Ubuntu’s APT (Advanced Packaging Tool) library to perform installation of new software packages, removing existing software packages, upgrading of existing software packages and even used to upgrading the entire operating system.

apt-get update

This will help us to download a list of packages from different repositories included on our system and updates them when there are new versions of packages and their dependencies. (After any modification in repositories we have to run apt-update manually other wise, system local cache from previous repositories will be used)

to see what packages can be upgraded:

apt-get upgrade

The ‘upgrade‘ command is used to upgrade all the currently installed software packages on the system. Under any circumstances currently installed packages are not removed or packages which are not already installed neither retrieved and installed to satisfy upgrade dependencies.

New versions of currently installed packages that cannot be upgraded without changing the install status of another package will be left at their current version.

An update must be performed first so that apt-get knows that new versions of packages are available.

apt-get dist-upgrade

dist-upgrade in addition to performing the function of upgrade, also intelligently handles changing dependencies with new versions of packages (including the kernel)

If we want to upgrade, unconcerned of whether software packages will be added or removed to fulfill dependencies, use the ‘dist-upgrade‘ sub command.

apt-get has a "smart" conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary.

apt-get autoremove

The ‘autoremove‘ sub command is used to auto remove packages that were certainly installed to satisfy dependencies for other packages and but they were now no longer required. For example:

apt-get install

Install a package as follows by specify a single package name or install many packages at once by listing all their names:

apt-get remove

Remove Packages without their Configuration Files:

apt-get purge

apt with remove, it only removes the package files but configuration files remain on the system. Therefore to remove a package and it’s configuration files, we will have to use purge.

apt-get clean

To delete downloaded packages (.deb) already installed (and no longer needed) and it would free up more space by cleaning the cache.

apt-get autoclean

To remove all stored archives in your cache for packages that can not be downloaded anymore (thus packages that are no longer in the repository or that have a newer version in the repository).

apt-get check

Will check the the currently installed packages for any broken installation.

What is apt-cache?

The apt-cache command line tool is used for searching apt software package cache. In simple words, this tool is used to search software packages, collects information of packages and also used to search for what available packages are ready for installation on Debian or Ubuntu based systems. APTs cached files are located in/var/cache/apt/archives/

Before start using apt-cache it is good to do apt-get check first:

Because this command builds new cache by comparing the current state with the state of packages as listed in repositories. One the apt-cache has been built we can query it.

apt-cache search

Find Out Package Name and Description of Software (doesn't require root access because it is querying the cache)

apt-cache show

Check information of package along with it short description say (version number, check sums, size, installed size, category etc).

apt-cache showpkg

‘showpkg‘ sub command to check the dependencies for particular software packages. whether those dependencies packages are installed or not.

apt-cache depends and apt-cache rdepends allow us to query dependencies.

See telnet dependencies and see which other packages depends on telnet.

use apt-cache stat to show statistics of installed packages on your computer.

dselect

dselect is a front-end to dpkg that is used to manage software packages in Debian and Debian-based Linux distributions. You can use dselect to install packages on your system from the APT archives defined in /etc/apt/sources.list, review the already installed packages, uninstall and upgrade packages.

aptitude

aptitude is another high-level package manager for Debian-based systems, and can be used to perform management tasks (installing, upgrading, and removing packages, also handling dependency resolution automatically) in a fast and easy way. It provides the same functionality as apt-get and additional ones, such as offering access to several versions of a package.

You might need to install aptitude first ( apt-get install aptitude )

As an example lets search and get info about netcat using aptitude:

Differences Between APT and Aptitude

Apart from main difference being that Aptitude is a high-level package manager while APT is lower-level package manager which can be used by other higher-level package managers, other main highlights that separate these two package managers are:

  • Aptitude is vaster in functionality than apt-get and integrates functionalities of apt-get and its other variants including apt-cache and apt-mark.

  • While apt-get lacks UI, Aptitude has a text-only and interactive UI

  • Aptitude has a better package management than apt-get:

1.While removing any installed package, Aptitude will automatically remove unused packages, while apt-get would need user to explicitly specify this by either adding additional option of ‘—auto-remove’ or specifying ‘apt-get autoremove’.

2.To investigate further as to why certain action is getting blocked or why or why-not a certain action should be taken, Aptitude offers 'why' and ‘why-not’ commands.

3.While apt-get would probably die-out in case of conflicting action regarding installation or removal of package with a message, Aptitude can suggest possible measures to remove that conflict.

Summary

Debian Family System

dpkg:

  • low-level or underlying packet manager

  • Unpacks, installs, removes and build packages

  • It can't download or resolve dependencies

Advance Package Tool (apt) :

  • Build on top of dpkg (depends on it)

  • works with groups of packages

  • It can automatically download and install packages to figure out and resolve dependencies.

  • Tts native user interface is through the apt-get and apt-cache commands

  • Usually a user interface is created on top of it for an specific distro (SW update GUIs are an example of this)

.

.

.

sources:

http://www.pepedocs.com/notes?tid=linux&nid=lfs101x

https://www.dennyzhang.com/linux_package_mgmt

https://www.networkworld.com/article/3305810/linux/how-to-list-repositories-on-linux.html

https://help.ubuntu.com/lts/serverguide/dpkg.html.en

https://www.tecmint.com/dpkg-command-examples/

https://geek-university.com/linux/dselect/( like dpkg but has UI)

https://unix.stackexchange.com/questions/20504/the-difference-between-deb-versus-deb-src-in-sources-list

https://askubuntu.com/questions/58364/whats-the-difference-between-multiverse-universe-restricted-and-main

https://www.tecmint.com/apt-advanced-package-command-examples-in-ubuntu/

https://wiki.debian.org/debconf

https://www.tecmint.com/useful-basic-commands-of-apt-get-and-apt-cache-for-package-management/

https://www.tecmint.com/apt-advanced-package-command-examples-in-ubuntu/

https://askubuntu.com/questions/32191/how-do-i-remove-cached-deb-files

https://askubuntu.com/questions/81585/what-is-dist-upgrade-and-why-does-it-upgrade-more-than-upgrade

https://askubuntu.com/questions/222348/what-does-sudo-apt-get-update-do

https://www.tecmint.com/linux-package-management/

https://www.tecmint.com/difference-between-apt-and-aptitude/

Last updated

Was this helpful?