Installing software with package managers

Linux · Essentials · 9 min

Package managers install software with dependencies and security updates; manual installs rot.

Distributions ship software as packages from signed repositories. The package manager resolves dependencies, installs files, records what owns each file and later upgrades everything together, including security fixes. That is why the first answer to "how do I install X" should be the package manager.

On Debian and Ubuntu (apt, .deb):

  • sudo apt update refreshes the package lists (do this first),
  • sudo apt install pkg, sudo apt remove pkg (purge also deletes config), sudo apt upgrade,
  • apt search term, apt show pkg, dpkg -L pkg lists a package's files, dpkg -S /path finds the owner of a file.

On Fedora, RHEL, Rocky and Alma (dnf, .rpm): sudo dnf install pkg, dnf remove, dnf upgrade, dnf search, dnf provides /usr/bin/dig and rpm -ql pkg. Others: pacman -S on Arch, apk add on Alpine, zypper on SUSE.

Extra repositories (PPAs, EPEL, vendor repos for Docker or PostgreSQL) add software the distribution does not carry; only add sources you trust, since packages install as root. Universal formats like Snap and Flatpak bundle dependencies for desktop apps. Language package managers (pip, npm) should not write into system directories: use virtual environments or per-user installs.

Example

# Debian / Ubuntu
sudo apt update                  # refresh package lists first
sudo apt install -y htop         # install with dependencies
apt search ripgrep               # find packages
apt show nginx | head -n 5       # version, size, description
sudo apt upgrade                 # update everything installed
sudo apt remove htop             # purge would also delete its config
dpkg -L curl | head -n 3         # files installed by a package
dpkg -S /usr/bin/ssh             # openssh-client: /usr/bin/ssh
# Fedora / RHEL
sudo dnf install htop
dnf provides /usr/bin/dig        # which package ships a file
# Arch: sudo pacman -S htop     Alpine: apk add htop

Remember

  • apt update before apt install; dnf on the RPM side
  • dpkg -S / dnf provides find which package owns a file
  • Prefer distribution packages; add only trusted repositories

Watch out for

  • Installing with sudo pip install into the system Python and breaking OS tools.

Check yourself

  1. On Ubuntu, `apt install foo` says 'Unable to locate package' for a package that exists. What should you try first?
  2. How do you find which package provides /usr/bin/dig on Fedora?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: manpages.debian.org/stable/apt/apt.8.en.html

Builds on

Unlocks

Nothing builds on this yet.