Advanced
Searching inSummaries
How to search
  • Words find lesson titles, text and code. Filter by type (guides, courses, programs, books) or stay in this book.
  • book:rhcsa and ch:8 narrow the search; #code finds a word only in commands of the lessons.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

Chapter 14Name in the book: Package Management

Install and manage software packages

On Linux you rarely download programs from websites. You install packages from the repositories of your distribution with one command. This chapter explains the two big package families (Debian and Red Hat), the high-level and low-level tools, and the daily tasks: search, install, remove, update and ask questions about packages.

  • 10 Lessons
  • 4 Commands
  • 1 Labs

$ run as a normal user# run as root (or with sudo)

Skills in this chapter

  • Install, update and query packages on Debian and Red Hat systems

14.1

Know the two package families

Most distributions use either .deb packages (the Debian family) or .rpm packages (the Red Hat family).

FamilyDistributionsPackage fileLow-level toolHigh-level tool
DebianDebian, Ubuntu, Linux Mint, Raspberry Pi OS.debdpkgapt, apt-get
Red HatFedora, RHEL, CentOS Stream, AlmaLinux, Rocky, openSUSE.rpmrpmdnf (yum on old systems), zypper on openSUSE

14.2

Understand packages, repositories and dependencies

A package is one archive with the program files, information and install scripts. A repository is a server full of packages. Dependencies are other packages a program needs.

  • The packages are built and tested by the distribution's package maintainers.
  • Programs share code in shared libraries. If a package needs a library, the package tool installs it too.
  • High-level tools (apt, dnf) download from repositories and solve dependencies. Low-level tools (dpkg, rpm) only install a package file you already have.

14.4

Install a package

Installing from a repository is one command as root. Dependencies come automatically.

sudo apt update
sudo apt install emacs
sudo dnf install emacs
sudo dpkg -i emacs-29.deb
sudo rpm -i emacs-29.rpm
FromDebianRed Hat
A repositoryapt install packagednf install package
A package filedpkg -i file.debrpm -i file.rpm

Watch out

dpkg -i and rpm -i do not install dependencies. If one is missing, they stop with an error. apt install ./file.deb and dnf install ./file.rpm install a local file with its dependencies.

14.5

Remove a package

Removing works with the package name, not the file name.

sudo apt remove emacs
sudo dnf remove emacs

14.6

Update the system

The most common task: bring all installed packages up to date with one command.

sudo apt update; sudo apt upgrade
sudo dnf upgrade
sudo dpkg -i emacs-30.deb
sudo rpm -U emacs-30.rpm
TaskDebianRed Hat
Update all from the repositoriesapt update; apt upgradednf upgrade
Upgrade from a package filedpkg -i file.debrpm -U file.rpm

At work

On servers, look at what will change before you say yes. Install security updates often; plan bigger upgrades.

14.7

Ask questions about packages

The low-level tools answer questions: what is installed, is X installed, what is in it, which package owns this file?

QuestionDebianRed Hat
List all installed packagesdpkg -lrpm -qa
Is package X installed?dpkg -s Xrpm -q X
Information about an installed packageapt show Xdnf info X
Which package installed this file?dpkg -S /path/filerpm -qf /path/file
Which files are in the package?dpkg -L Xrpm -ql X
rpm -qa | wc -l
rpm -q openssh-server
openssh-server-9.9p1-7.el10.x86_64
rpm -qf /usr/bin/vim
vim-enhanced-9.1.083-5.el10.x86_64
dpkg -S /bin/ls
coreutils: /bin/ls

14.8

Know the universal package formats

Snap, Flatpak and AppImage bundle a program with all its libraries, so one package runs on many distributions.

FormatFromNote
SnapCanonical (Ubuntu)Runs in a sandbox, updates itself
FlatpakStarted at Red Hat, now used widelyDesktop apps from Flathub, sandbox
AppImageCommunityOne file; make it executable and run it
  • Good: build once, run everywhere; some run in a sandbox.
  • Bad: very big packages, slow start, less integration with the system. The author of the book does not recommend them while the problems remain; normal repository packages fit the system best.

14.9

Know the "hard to install" myth

Software is not hard to install on Linux. Open-source programs are packaged by the distribution, so you get them in one place, tested and updated together.

  • The problem is mostly for companies that ship closed binary software: they must build for many distributions.
  • If a program is not in the repositories, you can build it from the source code (see Compile programs from source).

14.10

Summary of the chapter

apt / dnf for repositories, dpkg / rpm for package files and questions.

1Which command shows the package that installed /usr/bin/vim on Fedora?
2Why should you run apt update before apt install?

It downloads the newest package lists from the repositories.

3What is the difference between rpm -i file.rpm and dnf install ./file.rpm?

rpm -i does not get missing dependencies; dnf installs them from the repositories.

Practice

All commands in this chapter