Skip to content

Apt package manager

Upgrading

full-upgrade

sudo apt clean
sudo apt --fix-broken install
sudo apt update -m
sudo dpkg --configure -a
sudo apt install -f
sudo apt full-upgrade

Upgrade to next Debian release

see ../major-upgrade.md

Purge

apt purge $(dpkg -l | grep ^rc | awk '{print $2}')

Add apt repo in secure manner

https://wiki.debian.org/DebianRepository/UseThirdParty

apt install --no-install-recommends ...

Add next release to apt sources

export next_release="bookworm"
sudo cat << EOF > /etc/apt/sources.list.d/${next_release}.list
deb http://deb.debian.org/debian ${next_release} main
deb http://deb.debian.org/debian ${next_release}-updates main
EOF

sudo cat << EOF > /etc/apt/preferences.d/${next_release}
Explanation: Debian testing
Package: *
Pin: release o=Debian,n=${next_release}
Pin-Priority: 2
EOF

sudo apt update

Add debian testing to apt sources

Warning: testing doesn't provide security updates, so better use codenames like buster !!!

sudo cat << EOF > /etc/apt/sources.list.d/buster.list
deb http://deb.debian.org/debian/ testing main
deb http://deb.debian.org/debian/ testing-updates main
EOF

sudo cat << EOF > /etc/apt/preferences.d/testing
Explanation: Debian testing
Package: *
Pin: release o=Debian,a=testing
Pin-Priority: 2
EOF

sudo apt update

Extract a .deb file without opening it on Debian or Ubuntu Linux

dpkg-deb -xv htop_2.0.1-1ubuntu1_amd64.deb $(mktemp)

Backports

https://backports.debian.org/Instructions/

Setup backports:

echo "deb http://deb.debian.org/debian $(lsb_release -cs)-backports main" > /etc/apt/sources.list.d/backports.list
apt update

List manually installed packages

~/bin/apt-manually-installed-packages.py

List installed packages with their source

apt-forktracer Website

apt-forktracer a utility for managing Debian package versions It lets you find out which packages in the system are installed in non-official versions

apt install apt-forktracer
apt-forktracer

List non-free packages

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

Add 3rd party repo signing key

How To Handle apt-key and add-apt-repository Deprecation Using gpg to Add External Repositories on Ubuntu 22.04

curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/microsoft.gpg

List installed debs

apt-mark showmanual > ~/home/varac/ubuntu-migration.20121205.txt
apt-mark showmanual > ~/ubuntu-migration.now.txt
diff ~/ubuntu-migration.20121205.txt ~/ubuntu-migration.now.txt

Purge residual packages (config leftovers from uninstalled packages)

apt-get purge $(dpkg -l | awk '/^rc/ { print $2 }')

dpkg

dpkg --compare-versions 0.6.24-1 gt 0.6b3 && echo yes

Pinning

Pin version:

Pin: version 2.3.3-20180415.190957~artful1

Add Debian testing repo:

$ cat <<EOF > /etc/apt/preferences.d/testing.pref
Package: *
Pin: release a=testing
Pin-Priority: 1
EOF

echo "deb http://deb.debian.org/debian testing main" > /etc/apt/sources.list.d/testing.list
apt update

Remove unneded packages

apt autoremove --purge
deborphan | dpkg --purge
dpkg -l | grep ^rc | awk '{print $2}' | dpkg --purge
apt-forktracer
while deborphan -n | grep -q . ; do apt purge $(deborphan -n); done