Installing software across distributions
apt, dnf, pacman, snap and flatpak, repository priorities, and what to do when no package exists.
The families and their tools
Linux distributions ship a package manager that resolves dependencies against signed repositories. The commands differ; the model is identical — refresh the index, then ask for a package by name.
| Family | Low-level tool | Install | Search | Query a file |
|---|---|---|---|---|
| Debian / Ubuntu | dpkg | apt install nginx | apt search nginx | dpkg -S /usr/sbin/nginx |
| RHEL / Fedora | rpm | dnf install nginx | dnf search nginx | rpm -qf /usr/sbin/nginx |
| Arch | pacman | pacman -S nginx | pacman -Ss nginx | pacman -Qo /usr/bin/nginx |
| SUSE | rpm | zypper install nginx | zypper search nginx | rpm -qf /usr/sbin/nginx |
| Alpine | apk | apk add nginx | apk search nginx | apk info --who-owns /usr/sbin/nginx |
⚠️
Refreshing the index and upgrading are different operations.
apt update only downloads metadata; apt upgrade changes installed packages. Never run an unattended full upgrade on a production host without a maintenance window and a snapshot, and never reach for --force-yes or dpkg --force-overwrite to push a broken dependency through.apt and dpkg in practice
sudo apt update # refresh the package index
sudo apt install nginx
sudo apt install -y --no-install-recommends nginx # leaner server install
sudo apt upgrade # safe, keeps packages back if needed
sudo apt full-upgrade # may remove packages to satisfy dependencies
apt list --upgradable
apt-cache policy nginx # installed vs candidate version, which repo
apt-cache show nginx | head -20
dpkg -l | grep nginx # is it installed, and which version
dpkg -L nginx # every file the package shipped
dpkg -S /etc/nginx/nginx.conf # which package owns this file
sudo apt-mark hold nginx # freeze a version
sudo apt-mark unhold nginx
sudo apt autoremove # drop orphaned dependencies# add a third-party repository the careful way
curl -fsSL https://example.com/key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/example.gpg
echo "deb [signed-by=/usr/share/keyrings/example.gpg] https://example.com/apt stable main" |
sudo tee /etc/apt/sources.list.d/example.list
sudo apt update- A
deb822.sourcesfile is the modern replacement for one-line.listentries; both forms work today. - Pinning (/etc/apt/preferences.d) decides which repository wins when two offer the same package.
- If dpkg is interrupted,
sudo dpkg --configure -afinishes the job before you install anything else.
Beyond the system package manager
| Option | Ships | Best for |
|---|---|---|
| Distribution package | System libraries linked in | Daemons and anything a service depends on |
| snap | Squashed image, auto-updating | Desktop apps and fast-moving toolchains |
| flatpak | Sandboxed runtime + app | GUI applications with controlled permissions |
| Container image | Whole userspace | Deploying your own application |
| Build from source | Whatever you compile | A version or patch no repository carries |
sudo dnf install nginx
sudo dnf history # every transaction, and its id
sudo dnf history undo 42 # roll one back
dnf provides "*/nginx.conf" # which package ships this path
sudo pacman -Syu # refresh and upgrade together (Arch)
# building from source when no package fits
sudo apt install build-essential pkg-config
./configure --prefix=/usr/local && make -j"$(nproc)" && sudo make install./configure && make && make installleaves no record, so nothing upgrades or removes it later. Prefercheckinstall, or a static binary in/usr/local/bin, or a container.- Compiling with
--prefix=/usr/localavoids fighting the distribution over/usr. - Whatever route you take, pin the version in a config file or an image tag so a rebuild produces the same result.
FAQ
apt says the package is already the newest version but my binary is old?
You are probably running a different binary earlier in
PATH — check which -a nginx and dpkg -S. A leftover /usr/local install shadows the packaged one.Is it safe to mix snap and apt versions of the same tool?
It works but invites confusion, because each has its own version, config location and upgrade timing. Pick one delivery channel per tool and make the shell find only that one.
Related
Users, groups and privilege Archiving, syncing and backups
Last refreshed 2026-09-18.