To install software on Linux, a single command is enough:
sudo apt install name (Debian/Ubuntu) or sudo dnf install name
(RHEL/Fedora). This guide shows you how to search for, install,
check and remove packages with confidence.
What you will learn
- Refresh the list of packages available
- Search for a package by name or keyword
- Install a package and check that it works
- Remove a package cleanly
- List the packages already installed
How do you refresh the package list?
Before any installation, you must refresh the list of available packages. Without this step, your system does not know the latest versions, and may not even know a package exists.
sudo apt updateHit:1 http://archive.ubuntu.com/ubuntu noble InReleaseGet:2 http://security.ubuntu.com/ubuntu noble-security InReleaseReading package lists... DoneThis command changes nothing on your system. It only downloads the up-to-date list of available packages and versions.
sudo dnf check-updateDNF refreshes its metadata automatically. This command shows
the packages that have a newer version available. An exit code of 100
means that updates exist: it is normal.
Get into the habit of running apt update, or dnf check-update, before
each installation session. Without this refresh, your machine
works on an out-of-date catalogue: it may install an outdated
version, or refuse a package that is actually available with an E: Unable to locate package that seems incomprehensible.
How do you search for a package?
You do not know the exact name of the package? Use the search, which looks through names and descriptions:
apt search text editorTo show the details of a package you found:
apt show vimPackage: vimVersion: 2:9.1.0016-1ubuntu7.20Description: Vi IMproved - enhanced vi editordnf search text editorTo show the details of a package you found:
dnf info vim-enhancedName : vim-enhancedVersion : 9.1.083Summary : A version of the VIM editor which includes recent enhancementsSearch in English: package descriptions are written in English, and a
search in another language usually returns nothing. On Ubuntu 24.04, the
French words apt search editeur texte find no result, where
apt search text editor finds 96 (measured).
Remember too that the package name does not always match the software
name. The Vim editor installs from vim on Debian and from
vim-enhanced on RHEL, and the case is frequent as soon as a piece of software is
split into several packages. That is precisely what search is for:
running it before install costs a few seconds and avoids a No match for argument.
How do you install a package?
The three steps below go from the installation itself to the check that the command works, then to the package that provides it.
-
Start the installation with
sudo(packages are installed in system directories that require administrator rights):Terminal window sudo apt install treeAPT shows the list of packages that will be installed:
Output on Ubuntu 24.04 The following NEW packages will be installed:tree0 upgraded, 1 newly installed, 0 to remove and 92 not upgraded.When only the requested package is added, APT installs it without asking. As soon as it must add dependencies, it lists them and asks for confirmation: type
Y(or Enter) to accept.Terminal window sudo dnf install treeDNF shows a summary and asks for confirmation:
Output on AlmaLinux 10 Installing:tree x86_64 2.1.0-8.el10 baseosTransaction SummaryInstall 1 PackageIs this ok [y/N]:Type
yto confirm. -
Check that the installation worked:
Terminal window tree --versionOutput on Ubuntu 24.04 tree v2.1.1 (c) 1996 - 2023 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke TokoroIf the command prints a version number, the software is installed.
-
Check which package provides a command (useful when the name differs):
Terminal window dpkg -S "$(command -v tree)"Output tree: /usr/bin/treeTerminal window rpm -qf "$(command -v tree)"Output tree-2.1.0-8.el10.x86_64
Install several packages at once
You can install several packages in the same command, separated by spaces:
sudo apt install wget tree htopsudo dnf install wget treehtop is left out on purpose here: on RHEL and AlmaLinux, it is not in the
base repositories but in EPEL, and a single name that cannot be found makes
the whole command fail (Unable to find a match: htop, measured on
AlmaLinux 10). On AlmaLinux or Rocky, enable EPEL first with
sudo dnf install epel-release.
How do you remove a package?
Removing is as simple as installing, but APT offers two levels: keep the configuration files or delete them too.
Simple removal (keeps the configuration files):
sudo apt remove treeComplete removal (also deletes the configuration files):
sudo apt purge treeCheck: the command must no longer be available:
tree --versionbash: tree: command not foundsudo dnf remove treeDNF removes the package and can offer to remove the dependencies that are no longer needed.
Check:
tree --versionbash: tree: command not foundIf you had run tree in the same terminal before the removal, Bash
answers bash: /usr/bin/tree: No such file or directory instead: it had
remembered the path of the command. The package is really gone; hash -r
clears that memory.
How do you list installed packages?
To see which software is already installed on your system, query the package database directly:
dpkg -l | head -20To check whether a given package is installed:
dpkg -l treerpm -qa | head -20To check whether a given package is installed:
rpm -q treeHow do you reinstall a package?
If a piece of software no longer works properly, you can reinstall it without removing it first. The package files are put back in place, which repairs a deleted or damaged file:
sudo apt reinstall treesudo dnf reinstall treeTroubleshooting
These 5 symptoms cover almost every installation failure
met at the start, and they have one thing in common: none comes from the package
itself. The cause is almost always an out-of-date list, an inexact
name, or a forgotten sudo. Read the left column as the exact message
displayed, and try the fix on the right before looking further.
| Symptom | Likely cause | Fix |
|---|---|---|
E: Unable to locate package | Package list out of date | sudo apt update then try again |
No match for argument | Wrong package name | Check with dnf search keyword |
E: Could not open lock file ... (13: Permission denied) (APT) or This command has to be run with superuser privileges (DNF) | Command run without sudo | Add sudo in front of the command |
| Removal takes away too many packages | Reverse dependencies | Answer n, check the dependencies |
| Package installed but command not found | The binary has another name | Look with dpkg -L name or rpm -ql name |
Key points
- Always
apt update(ordnf check-update) before installing. apt install/dnf installhandle dependencies automatically.apt search/dnf searchfind the right package name: search in English.apt removekeeps the configuration;apt purgedeletes everything.- Always read the summary before confirming an installation or a removal.
- Check with
command --versionthat the installation worked.
Knowledge check
Check that the essentials of this guide stuck. The questions cover only what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Update your Linux system
A new full quiz with random questions
Work again only on the questions you missed