$ 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
Know the two package families
Most distributions use either .deb packages (the Debian family) or .rpm packages (the Red Hat family).
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.
Find a package
Search the repository by a name or a word in the description.
apt update
apt search emacs
dnf search emacs| Family | Command |
|---|---|
| Debian | apt update; apt search search_string |
| Red Hat | dnf search search_string |
Remember
On Debian systems run apt update first. It downloads the newest package lists; without it, the search results may be old.
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| From | Debian | Red Hat |
|---|---|---|
| A repository | apt install package | dnf install package |
| A package file | dpkg -i file.deb | rpm -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.
Remove a package
Removing works with the package name, not the file name.
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| Task | Debian | Red Hat |
|---|---|---|
| Update all from the repositories | apt update; apt upgrade | dnf upgrade |
| Upgrade from a package file | dpkg -i file.deb | rpm -U file.rpm |
At work
On servers, look at what will change before you say yes. Install security updates often; plan bigger upgrades.
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?
| Question | Debian | Red Hat |
|---|---|---|
| List all installed packages | dpkg -l | rpm -qa |
| Is package X installed? | dpkg -s X | rpm -q X |
| Information about an installed package | apt show X | dnf info X |
| Which package installed this file? | dpkg -S /path/file | rpm -qf /path/file |
| Which files are in the package? | dpkg -L X | rpm -ql X |
Know the universal package formats
Snap, Flatpak and AppImage bundle a program with all its libraries, so one package runs on many distributions.
| Format | From | Note |
|---|---|---|
| Snap | Canonical (Ubuntu) | Runs in a sandbox, updates itself |
| Flatpak | Started at Red Hat, now used widely | Desktop apps from Flathub, sandbox |
| AppImage | Community | One 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.
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).
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.