Debian Package Management

Debian Package Management

Debian Based Linux Distribution: (Debian, Ubuntu, Linux Mint,etc)
When it comes to managing your software, Linux distributions make it fairly
easy to install, update, or remove installed programs. This is mostly done with
package managers. Today i will be going over Debian’s package manager. dpkg is
the software at the core of the package management system for Debian. It is used
to install, remove, and provide information about .deb packages. This is
considered a low-level tool. We more commonly use apt. apt is more commonly used
then dpkg because it has can also fetch packages from remote locations , as well
as deal with complex package relations, such as resolving dependencies. On top
of that, there are front ends for apt such as aptitude, a program written with
ncurses, and synaptic, a program written with GTK+, which will provide a
friendlier interface for users. Lets run dpkg with the help command

clim@debian:~$ dpkg --help
Usage: dpkg [

  -i|--install       ... | -R|--recursive ...
  --unpack           ... | -R|--recursive ...
  -A|--record-avail  ... | -R|--recursive ...
  --configure        ... | -a|--pending
  --triggers-only    ... | -a|--pending
  -r|--remove        ... | -a|--pending
  -P|--purge         ... | -a|--pending
  -V|--verify [...]       Verify the integrity of package(s).
  --get-selections [...]  Get list of selections to stdout.
  --set-selections                 Set package selections from stdin.
  --clear-selections               Deselect every non-essential package.
  --update-avail [] Replace available packages info.
  --merge-avail []  Merge with info from file.
  --clear-avail                    Erase existing available info.
  --forget-old-unavail             Forget uninstalled unavailable pkgs.
  -s|--status [...]       Display package status details.
  -p|--print-avail [...]  Display available version details.
  -L|--listfiles ...      List files 'owned' by package(s).
  -l|--list [...]         List packages concisely.
  -S|--search ...         Find package(s) owning file(s).
  -C|--audit [...]        Check for broken package(s).
  --yet-to-unpack                  Print packages selected for installation.
  --predep-package                 Print pre-dependencies to unpack.
  --add-architecture         Add  to the list of architectures.
  --remove-architecture      Remove  from the list of architectures.
  --print-architecture             Print dpkg architecture.
  --print-foreign-architectures    Print allowed foreign architectures.
  --assert-               Assert support for the specified feature.
  --validate-       Validate a 's .
  --compare-versions <a>  <b>  Compare version numbers - see below.
  --force-help                     Show help on forcing.
  -Dh|--debug=help                 Show help on debugging.

  -?, --help                       Show this help message.
      --version                    Show the version.

Assertable features: support-predepends, working-epoch, long-filenames,
  multi-conrep, multi-arch, versioned-provides.

Validatable things: pkgname, archname, trigname, version.

Use dpkg with -b, --build, -c, --contents, -e, --control, -I, --info,
  -f, --field, -x, --extract, -X, --vextract, --ctrl-tarfile, --fsys-tarfile
on archives (type dpkg-deb --help).

  --admindir=     Use  instead of /var/lib/dpkg.
  --root=         Install on a different root directory.
  --instdir=      Change installation dir without changing admin dir.
  --path-exclude=   Do not install paths which match a shell pattern.
  --path-include=   Re-include a pattern after a previous exclusion.
  -O|--selected-only         Skip packages not selected for install/upgrade.
  -E|--skip-same-version     Skip packages whose same version is installed.
  -G|--refuse-downgrade      Skip packages with earlier version than installed.
  -B|--auto-deconfigure      Install even if it would break some other package.
  --[no-]triggers            Skip or force consequential trigger processing.
  --verify-format=   Verify output format (supported: 'rpm').
  --no-debsig                Do not try to verify package signatures.
                             Just say what we would do - don't do it.
  -D|--debug=         Enable debugging (see -Dhelp or --debug=help).
  --status-fd             Send status change updates to file descriptor .
  --status-logger=  Send status change updates to 's stdin.
  --log=           Log status changes and actions to .
                             Ignore dependencies involving .
  --force-...                Override problems (see --force-help).
                             Stop when problems encountered.
  --abort-after           Abort after encountering  errors.

Comparison operators for --compare-versions are:
  lt le eq ne ge gt       (treat empty version as earlier than any version);
  lt-nl le-nl ge-nl gt-nl (treat empty version as later than any version);
  &lt; &lt;&lt; = &gt;&gt; &gt;       (only for compatibility with control file syntax).

Use 'apt' or 'aptitude' for user-friendly package management.

So there is alot to take in here, lets start with some basic examples. If I
wanted to manually install a debian package, after downloading the package i
would then use:

clim@debian:~$ sudo dpkg -i filename.deb

Just a quick note, i use sudo to switch to root to install the package. Next
if i just wanted to name the packages that are currently installed, i can use

clim@debian:~$ dpkg -l

And to remove a package its simply

clim@debian:~$ dpkg -r packagename

If you ever stop an upgrade while it is running you may need to run:

clim@debian:~$sudo dpkg --configure -a

This will require administrative privileges so using sudo is required for this
as well as installing packages. Lets go over apt now.
APT stands for Advanced Package Tool. It is a free-software user interface
which works with core libraries to handle software. It simplifies the process of
managing software on Debian-based systems by automating the retrieval,
configuration and installation of software packages. Its done by either
pre-compiled binaries, or compiling the source code. The manpage for this one is
a bit more formatted:

clim@debian:~$man apt
APT(8)                                APT                               APT(8)

       apt - command-line interface

       apt [-h] [-o=config_string] [-c=config_file] [-t=target_release]
           [-a=architecture] {list | search | show | update |
           install pkg [{=pkg_version_number | /target_release}]...  |
           remove pkg...  | upgrade | full-upgrade | edit-sources |
           {-v | --version} | {-h | --help}}

       apt provides a high-level commandline interface for the package
       management system. It is intended as an end user interface and enables
       some options better suited for interactive usage by default compared to
       more specialized APT tools like apt-get(8) and apt-cache(8).

       Much like apt itself, its manpage is intended as an end user interface
       and as such only mentions the most used commands and options partly to
       not duplicate information in multiple places and partly to avoid
       overwhelming readers with a cornucopia of options and details.

       update (apt-get(8))
           update is used to download package information from all configured
           sources. Other commands operate on this data to e.g. perform
           package upgrades or search in and display details about all
           packages available for installation.

       upgrade (apt-get(8))
           upgrade is used to install available upgrades of all packages
           currently installed on the system from the sources configured via
           sources.list(5). New packages will be installed if required to
           satisfy dependencies, but existing packages will never be removed.
           If an upgrade for a package requires the removal of an installed
           package the upgrade for this package isn't performed.

       full-upgrade (apt-get(8))
           full-upgrade performs the function of upgrade but will remove
           currently installed packages if this is needed to upgrade the
           system as a whole.

       install, reinstall, remove, purge (apt-get(8))
           Performs the requested action on one or more packages specified via
           regex(7), glob(7) or exact match. The requested action can be
           overridden for specific packages by append a plus (+) to the
           package name to install this package or a minus (-) to remove it.

           A specific version of a package can be selected for installation by
           following the package name with an equals (=) and the version of
           the package to select. Alternatively the version from a specific
           release can be selected by following the package name with a
           forward slash (/) and codename (buster, bullseye, sid ...) or suite
           name (stable, testing, unstable). This will also select versions
           from this release for dependencies of this package if needed to
           satisfy the request.

           Removing a package removes all packaged data, but leaves usually
           small (modified) user configuration files behind, in case the
           remove was an accident. Just issuing an installation request for
           the accidentally removed package will restore its function as
           before in that case. On the other hand you can get rid of these
           leftovers by calling purge even on already removed packages. Note
           that this does not affect any data or configuration stored in your
           home directory.

       autoremove (apt-get(8))
           autoremove is used to remove packages that were automatically
           installed to satisfy dependencies for other packages and are now no
           longer needed as dependencies changed or the package(s) needing
           them were removed in the meantime.

           You should check that the list does not include applications you
           have grown to like even though they were once installed just as a
           dependency of another package. You can mark such a package as
           manually installed by using apt-mark(8). Packages which you have
           installed explicitly via install are also never proposed for
           automatic removal.

       search (apt-cache(8))
           search can be used to search for the given regex(7) term(s) in the
           list of available packages and display matches. This can e.g. be
           useful if you are looking for packages having a specific feature.
           If you are looking for a package including a specific file try apt-

       show (apt-cache(8))
           Show information about the given package(s) including its
           dependencies, installation and download size, sources the package
           is available from, the description of the packages content and much
           more. It can e.g. be helpful to look at this information before
           allowing apt(8) to remove a package or while searching for new
           packages to install.

       list (work-in-progress)
           list is somewhat similar to dpkg-query --list in that it can
           display a list of packages satisfying certain criteria. It supports
           glob(7) patterns for matching package names as well as options to
           list installed (--installed), upgradeable (--upgradeable) or all
           available (--all-versions) versions.

       edit-sources (work-in-progress)
           edit-sources lets you edit your sources.list(5) files in your
           preferred texteditor while also providing basic sanity checks.

       The apt(8) commandline is designed as an end-user tool and it may
       change behavior between versions. While it tries not to break backward
       compatibility this is not guaranteed either if a change seems
       beneficial for interactive use.

       All features of apt(8) are available in dedicated APT tools like apt-
       get(8) and apt-cache(8) as well.  apt(8) just changes the default value
       of some options (see apt.conf(5) and specifically the Binary scope). So
       you should prefer using these commands (potentially with some
       additional options enabled) in your scripts as they keep backward
       compatibility as much as possible.

       apt-get(8), apt-cache(8), sources.list(5), apt.conf(5), apt-config(8),
       The APT User's guide in /usr/share/doc/apt-doc/, apt_preferences(5),
       the APT Howto.

       apt returns zero on normal operation, decimal 100 on error.

       APT bug page[1]. If you wish to report a bug in APT, please see
       /usr/share/doc/debian/bug-reporting.txt or the reportbug(1) command.

       APT team

        1. APT bug page

APT 1.8.2                       27 January 2019                         APT(8)

Some of the common things you may need to do is update the system as well as
upgrade. When you first install Debian, or Ubuntu, or whatever Debian-based
Linux Distribution you choose, you will most likely perform this command:

clim@debian:~$ sudo apt update && sudo apt upgrade
[sudo] password for clim:
Hit:1 buster/updates InRelease
Hit:2 buster InRelease
Hit:3 buster-updates InRelease
Hit:4 any InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

So what did i just do? Well first i ran apt update, which will update your
system to determine what programs have newer versions online, after you update
your repository, you then have to run upgrade to install the upgrades available.
I have ran this command fairly recently, so there is not any available upgrades.
So how did this work? Well the update command checks a specific file on your
computer for specific addresses of servers containing the packages.

clim@debian:~$ cat /etc/apt/sources.list

# deb cdrom:[Debian GNU/Linux 9.5.0 _Buster_ - Official amd64 NETINST 20180714-10:25]/ buster main

#deb cdrom:[Debian GNU/Linux 9.5.0 _Buster_ - Official amd64 NETINST 20180714-10:25]/ buster main

deb buster main
deb-src buster main

deb buster/updates main
deb-src buster/updates main

# buster-updates, previously known as 'volatile'
deb buster-updates main
deb-src buster-updates main

Lets break down this file located at /etc/apt/sources.list. The first string
determines if you are looking for packages (“deb”) or sources (“deb-src”). The
next string is the location of the repository. The third string is the version
name, Debian’s current version is Buster . And the last is just the main
repository, however there are others as well. Im not quite sure where the Atom
IDE repository is stored, as you saw above, it checked a third-party link to
ATOM. Maybe its stored in my /etc/apt/sources.list.d/ directory. This contains
additional source list fragments. I do believe i installed Atom via dpkg so I am
not quite sure. Well anyway. Your configuration file is at /etc/apt/apt.conf and
also contains a directory similar to the sources list that has file fragments (
located at /etc/apt/apt.conf.d/). You can also find archives in /var/cache/apt
And the storage area for package state information at /var/lib/apt/lists/ .
Those last couple are not really used by the user though, it may be useful to have
that information.
So apt’s main keywords you will use are: install , remove, update, upgrade ,
autoclean and dist-upgrade as such:

clim@debian:~$ sudo apt update
clim@debian:~$ sudo apt upgrade
clim@debian:~$ sudo apt install programName
clim@debian:~$ sudo apt remove programName
clim@debian:~$ sudo apt autoclean
clim@debian:~$ sudo apt dist-upgrade

For the last little piece of information, when you are installing, usually it
will come back with a list of suggested packages for extra features of your
program so you can use the flag –install-suggests as such:

clim@debian:~$ sudo apt install programName --install-suggests


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s