Package management cheatsheet.

apt (Debian/Ubuntu)

apt update
apt upgrade
apt full-upgrade                    # may remove packages
apt install nginx
apt install nginx=1.27.0-1
apt install --no-install-recommends nginx
apt remove nginx                    # keep config
apt purge nginx                     # remove config too
apt autoremove                      # unused deps
apt search nginx
apt show nginx
apt list --installed
apt list --upgradable
apt depends nginx
apt rdepends nginx                  # what depends on nginx
apt-cache policy nginx              # version + source

dpkg

dpkg -i pkg.deb                     # install
dpkg -r pkg                         # remove
dpkg -l                             # list installed
dpkg -L nginx                       # list files
dpkg -S /usr/sbin/nginx             # which pkg owns
dpkg --configure -a                 # fix interrupted install

dnf (Fedora/RHEL)

dnf install nginx
dnf upgrade
dnf remove nginx
dnf search nginx
dnf info nginx
dnf list installed
dnf history
dnf history undo 42
dnf provides /usr/sbin/nginx
dnf module list nginx
dnf module enable nginx:1.27

yum (older RHEL)

Similar to dnf; just replace dnf with yum.

rpm

rpm -ivh pkg.rpm                    # install
rpm -Uvh pkg.rpm                    # upgrade
rpm -e pkg                          # remove
rpm -qa                             # all installed
rpm -ql nginx                       # files
rpm -qf /usr/sbin/nginx             # which pkg
rpm -qi nginx                       # info

pacman (Arch)

pacman -Syu                         # sync + upgrade
pacman -S nginx
pacman -R nginx
pacman -Rns nginx                   # remove + deps + config
pacman -Ss nginx
pacman -Si nginx
pacman -Qi nginx
pacman -Ql nginx
pacman -Qo /usr/bin/nginx           # which pkg owns
pacman -Qdt                         # orphaned deps

AUR (Arch user repos)

yay -S package                      # via yay helper
paru -S package

apk (Alpine)

apk update
apk add nginx
apk upgrade
apk del nginx
apk search nginx
apk info -L nginx
apk info -W /usr/sbin/nginx

Container-friendly: apk add --no-cache nginx.

brew (macOS / Linux)

brew install nginx
brew upgrade
brew uninstall nginx
brew list
brew search nginx
brew info nginx
brew services start nginx          # macOS LaunchAgent
brew bundle install                 # from Brewfile

snap

snap install code --classic
snap refresh
snap remove code
snap list
snap find editor

flatpak

flatpak install flathub org.mozilla.firefox
flatpak run org.mozilla.firefox
flatpak update

Repositories

apt

/etc/apt/sources.list
/etc/apt/sources.list.d/*.list

Modern (deb822) at /etc/apt/sources.list.d/*.sources.

Add PPA / external:

apt install -y apt-transport-https
curl -fsSL https://example.com/key.gpg | gpg --dearmor -o /usr/share/keyrings/example.gpg
echo "deb [signed-by=/usr/share/keyrings/example.gpg] https://example.com/repo stable main" > /etc/apt/sources.list.d/example.list
apt update

dnf

/etc/yum.repos.d/*.repo
dnf config-manager --add-repo https://example.com/repo.repo
dnf install epel-release

Pinning versions

apt:

# /etc/apt/preferences.d/nginx
Package: nginx
Pin: version 1.27.*
Pin-Priority: 1001

dnf:

dnf install nginx-1.27.0
dnf versionlock add nginx

Unattended upgrades

apt:

apt install unattended-upgrades
dpkg-reconfigure unattended-upgrades

dnf:

dnf install dnf-automatic
systemctl enable --now dnf-automatic.timer

Hold pkg

apt:

apt-mark hold nginx
apt-mark unhold nginx

dnf:

dnf versionlock add nginx

Build from source (rare)

apt build-dep nginx                 # get build deps
apt source nginx

Universe / multiverse / non-free

add-apt-repository universe
add-apt-repository multiverse
add-apt-repository non-free non-free-firmware

Verify GPG

apt-key list                        # deprecated
ls /etc/apt/trusted.gpg.d/
ls /usr/share/keyrings/

Don’t apt-key add; place keys in /usr/share/keyrings/ and reference in sources file.

Common mistakes

  • apt-get vs apt — both work; apt is newer.
  • Forgetting apt update before install (stale package list).
  • --no-install-recommends makes images smaller but sometimes breaks things.
  • Mixing snap + apt for same app.
  • Pinning version without dependency pinning → broken deps.

Read this next

If you want my unattended-upgrades + apt cache setup, it’s at rajpoot.dev .


Building something AI-, backend-, or data-heavy and want a second pair of eyes? I do consulting and freelance work — see my projects and ways to reach me at rajpoot.dev .