Package manager

Which Package Manager?

Every distribution family ships its own package manager. Find yours in the table, then use the matching line in the sections below. Most install/remove operations need sudo.
Package managerDistribution
apt, apt-get, dpkgDebian, Ubuntu, Mint
dnf, yum, rpmFedora, RHEL, CentOS
pacmanArch, Manjaro
zypperopenSUSE
emergeGentoo
apkAlpine
pkgFreeBSD, Termux
snap, flatpakDistribution-independent app formats
apt is the friendlier front end to apt-get/apt-cache and the better choice for interactive use. On Fedora, dnf replaced yum.

Install from repository

$ apt install [packageName]
$ dnf install [packageName]
$ yum install [packageName]
$ pacman -S [packageName]
$ zypper install [packageName]
$ emerge -av [packageName]
$ apk add [packageName]
$ pkg install [packageName]
$ snap install [packageName]
$ flatpak install [remote] [packageName]

Install from file

$ dpkg -i [package.deb]
$ apt install ./[package.deb]
$ dnf install [package.rpm]
$ rpm -i [package.rpm]
$ pacman -U [package.pkg.tar.zst]
$ flatpak install [package.flatpakref]
$ pkg add [package.txz]
Prefer apt install ./package.deb over dpkg -i: apt resolves and installs missing dependencies, dpkg does not.

Remove/Uninstall

$ apt remove [packageName]
$ dnf remove [packageName]
$ yum remove [packageName]
$ pacman -Rs [packageName]
$ zypper remove [packageName]
$ emerge --depclean [packageName]
$ apk del [packageName]
$ pkg delete [packageName]
$ snap remove [packageName]
$ flatpak uninstall [packageName]
apt purge also deletes the package's system-wide configuration files; pacman -Rs removes the package together with dependencies nothing else needs.Clean up dependencies that are no longer needed by anything.
$ apt autoremove
$ dnf autoremove
$ pacman -Qdtq

Find a package

$ apt search [query]
$ apt-cache search [query]
$ dnf search [query]
$ yum search [query]
$ pacman -Ss [query]
$ zypper search [query]
$ emerge -S [query]
$ apk search [query]
$ pkg search [query]
$ snap find [query]
$ flatpak search [query]

View package info

$ apt show [packageName]
$ apt-cache show [packageName]
$ dpkg -s [packageName]
$ dnf info [packageName]
$ yum info [packageName]
$ pacman -Si [packageName]
$ zypper info [packageName]
$ apk info [packageName]
$ pkg info [packageName]
$ snap info [packageName]
$ pip show [packageName]

Update package lists

Refresh the list of available packages and versions without installing anything.
$ apt update
$ dnf check-update
$ yum check-update
$ zypper refresh
$ emerge --sync
$ apk update
$ pkg update

Upgrade installed packages

$ apt upgrade
$ dnf upgrade
$ yum update
$ pacman -Syu
$ zypper update
$ emerge -avuDN @world
$ apk upgrade
$ pkg upgrade
$ snap refresh
$ flatpak update
On Arch, always sync and upgrade together with pacman -Syu. Refreshing the database with -Sy and then installing single packages can break the system (partial upgrade).

Which package owns a file?

$ dpkg -S /usr/bin/[file]
$ dnf provides /usr/bin/[file]
$ rpm -qf /usr/bin/[file]
$ pacman -Qo /usr/bin/[file]
List the files a package installed.
$ dpkg -L [packageName]
$ rpm -ql [packageName]
$ pacman -Ql [packageName]

Add repository source

$ add-apt-repository ppa:[userName]/[ppaName]
$ dnf config-manager --add-repo [url]
$ yum-config-manager --add-repo [url]
$ zypper addrepo [url] [alias]
$ flatpak remote-add flathub https://flathub.org/repo/flathub.flatpakrepo

List installed packages

$ apt list --installed
$ dpkg -l
$ dnf list installed
$ rpm -qa
$ pacman -Q
$ zypper packages --installed-only
$ apk list --installed
$ snap list
$ flatpak list
$ pip list

AUR Helpers

On Arch, yay and paru install community packages from the AUR with the same flags as pacman.
$ yay -S [packageName]
$ paru -S [packageName]