tips
42 tips Apt
One command, setting or habit at a time about Apt: what it does, the line to copy and a caveat or two.
Packages 11
-
Swaps one package for another in a single apt transaction.
sudo apt-get -s install chrony systemd-timesyncd- -
Marks packages as dependencies so autoremove can remove them when nothing needs them.
sudo apt-mark auto build-essential libssl-dev -
Reruns the setup questions of an installed package, like time zone or locale.
sudo dpkg-reconfigure tzdata -
Diagnoses and fixes a package system left with unmet dependencies.
sudo apt-get check -
Installs packages from a dependency line with version constraints, and can remove conflicting ones.
sudo apt-get satisfy "libssl-dev (>= 3.0)" "pkg-config" -
Removes unused dependency packages together with their leftover configuration files.
sudo apt autoremove --purge -
Shows the maintainers' notes for a package so you know what an update actually changes.
apt changelog openssh-server -
Installs a package with only its required dependencies and skips the merely recommended ones.
sudo apt install --no-install-recommends -
Shows the installed version, the candidate version and which repository each comes from.
apt policy nginx -
Freezes one package at its current version while everything else keeps updating.
sudo apt-mark hold postgresql-16 -
Lists the packages that have a newer version available without installing anything.
apt list --upgradable
Inspecting packages 10
-
Prints a package's description, size, dependencies and source repository.
apt show nginx -
Searches package names only, so results don't drown in description matches.
apt-cache search --names-only zstd -
Lists packages that no longer exist in any configured repository, so they get no updates.
apt list '~o' -
Prints the merged configuration from every file in apt.conf.d.
apt-config dump | less -
Lists all available versions of a package and the repository for each.
apt-cache madison nginx -
Prints the packages you installed on purpose, which makes rebuilds easier.
apt-mark showmanual > packages.txt -
Lists all the files that an installed package has put on disk.
dpkg -L nginx-common | grep etc -
Tells you which installed package a given file belongs to.
dpkg -S /usr/bin/dig -
Finds which package provides a file, even when that package is not installed.
sudo apt install apt-file -
Lists installed packages that depend on a given package.
apt-cache rdepends --installed libssl3
Upgrading 7
-
Stops apt from asking about changed config files during scripted upgrades.
-o Dpkg::Options::="--force-confold" upgrade -
Fetches all upgrade packages ahead of time without installing anything.
sudo apt-get -d -y full-upgrade -
Explains the deferred due to phasing message and when to override it.
apt policy openssh-server -
Upgrades a named package only if it is already installed, and never installs it as new.
sudo apt-get install --only-upgrade nginx -
Shows what an install or upgrade would do without changing the system.
apt -s full-upgrade -
Lets apt install or remove packages to finish upgrades that are kept back.
sudo apt upgrade -
Lists the packages that are held back, so you can see why an upgrade skips them.
apt-mark showhold
Cleanup 5
-
Lets apt autoremove clean up dependencies of metapackages that were once marked manual.
sudo apt-mark minimize-manual -
Cleans out packages that are gone but still left their configuration behind.
apt list '~c' -
Removes only cached package files that can no longer be downloaded.
sudo apt-get -s autoclean -
Deletes cached package downloads to free disk space on the system.
sudo apt clean -
Reinstalls a package and restores config files that were deleted.
sudo apt install --reinstall coreutils
Files and sources 5
-
Makes apt download over IPv4 only when IPv6 connections stall.
sudo apt -o Acquire::ForceIPv4=true update -
Limits a third party key so it can only sign its own repository.
sudo install -d -m 0755 /etc/apt/keyrings -
Shows the newer repository format and how to disable a source cleanly.
Types: deb -
Installs a downloaded .deb file and pulls in the dependencies it needs.
sudo apt install ./vendor-tool_2.1_amd64.deb -
Tells apt which version of a package to prefer, and keeps it there.
Pin: version 1.24.*
Inspect and logs 4
-
Lists each install, upgrade and removal at dpkg level with versions and times.
grep -E ' (install|upgrade|remove) ' /var/log/dpkg.log | tail -
Shows the full terminal output of past apt runs, including install script errors.
sudo less /var/log/apt/term.log -
Shows which packages apt installed, upgraded or removed, on which date and by which command.
less /var/log/apt/history.log -
Saves a package as a .deb file in the current directory without installing it.
apt download htop
Nothing in this filter yet.