Apt/Deb

Tasks

Show packages belonging to non-free

dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-free

Search for packages that own files corresponding to the given pattern

$ apt search postgresql
# dpkg -S /usr/bin/host
bind9-host: /usr/bin/host

Downgrade a package

sh -c 'VER=5.8~bullseye; apt install winehq-staging=$VER wine-staging=$VER wine-staging-amd64=$VER wine-staging-i386=$VER'

Set a package on hold

me@computer:~$ apt-mark hold wine-staging wine-staging-amd64 wine-staging-i386:i386 winehq-staging
wine-staging set on hold.
wine-staging-amd64 set on hold.
wine-staging-i386:i386 set on hold.
winehq-staging set on hold.

Additionally, it is possible to create a /tmp/mypref file with this content:

Package: wine*:*
Pin: version 4.15~buster
Pin-Priority: 1001

and run the following:

me@computer:~$ apt -o Dir::Etc::Preferences=/tmp/mypref install winehq-staging wine-staging-amd64 wine-staging-i386 wine-staging
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be DOWNGRADED:
  wine-staging wine-staging-amd64 wine-staging-i386:i386 winehq-staging
0 upgraded, 0 newly installed, 4 downgraded, 0 to remove and 0 not upgraded.
Need to get 136 MB of archives.
After this operation, 1.371 kB disk space will be freed.
Do you want to continue? [Y/n]

Preferences

If we want to have the sid repositories enabled on our computer without actually switching to sid (running stable or testing), we set this preference file /etc/apt/preferences.d/99sid:

Package: *
Pin: release a=unstable
Pin-Priority: 110

This way, our sid packages keep being upgraded but the other packages belonging to another distribution won’t be upgraded to sid. In the following example, we see that the priority of the bullseye packages is 500 while the sid ones is 110. The currently installed packages have a priority of 100.

me@computer:~$ apt-cache policy linux-image-amd64
linux-image-amd64:
  Installed: 5.6.7-1
  Candidate: 5.6.7-1
  Version table:
 *** 5.6.7-1 500
        500 https://ftp-stud.hs-esslingen.de/debian bullseye/main amd64 Packages
        110 https://ftp-stud.hs-esslingen.de/debian sid/main amd64 Packages
        100 /var/lib/dpkg/status
     5.5.17-1~bpo10+1 100
        100 https://ftp-stud.hs-esslingen.de/debian buster-backports/main amd64 Packages
     4.19+105+deb10u4 500
        500 https://ftp-stud.hs-esslingen.de/debian buster/main amd64 Packages

Utilities

apt – command-line interface

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).

apt update --allow-releaseinfo-change

apt-file — APT package searching utility

Useful to search for files in not installed packages

Finding relevant cache files to search …E: The cache is empty. You need to run "apt-file update" first.
leo@computer:~$ apt-file search fence_scsi_check
fence-agents: /usr/share/cluster/fence_scsi_check
fence-agents: /usr/share/cluster/fence_scsi_check_hardreboot

apt-show-versions

apt-show-versions – Lists available package versions with distribution

leopardb@venus:~$ apt-show-versions | grep buster
libfaudio0:amd64 19.10-0~buster newer than version in archive
libfaudio0:i386 19.10-0~buster newer than version in archive
virtualbox-6.0:amd64/buster 6.0.14-133895~Debian~buster uptodate
wine-staging:amd64 4.17~buster newer than version in archive
wine-staging-amd64:amd64 4.17~buster newer than version in archive
wine-staging-i386:i386 4.17~buster newer than version in archive
winehq-staging:amd64 4.17~buster newer than version in archive
apt-show-versions | grep sid

deborphan – Orphaned package finder

apt remove `deborphan`
apt purge `deborphan`

apt-cache

apt-cache – query the APT cache

Get package version:

root@ansible ~# apt-cache policy bind9-host
bind9-host:
  Installed: 1:9.11.5.P4+dfsg-5.1+deb10u2
  Candidate: 1:9.11.5.P4+dfsg-5.1+deb10u2
  Version table:
 *** 1:9.11.5.P4+dfsg-5.1+deb10u2 500
        500 http://security.debian.org buster/updates/main amd64 Packages
        500 http://deb.debian.org/debian buster/main amd64 Packages
        100 /var/lib/dpkg/status

Get package dependencies:

apt-cache depends package-name
apt-cache rdepends package-name

apt-key (deprecated)

apt-key – APT key management utility

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88

pub   4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <docker@docker.com>
sub   4096R/F273FCD8 2017-02-22

Signatures/public keys

root@bareos:/etc/apt/sources.list.d# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E5D882B28657AE28
Executing: /tmp/apt-key-gpghome.of9N8ZWkz0/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys E5D882B28657AE28
gpg: key E5D882B28657AE28: public key "Bareos 19.2 Signing Key <signing@bareos.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1

Deprecated: gpg keys are stored in /etc/apt/trusted.gpg.d/

What should be used now:

https://www.linuxuprising.com/2021/01/apt-key-is-deprecated-how-to-add.html