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
- Check where a package comes from
How do you refresh the package list?
On Debian and Ubuntu, you must refresh the list of available packages before any installation. Without this step, your system does not know the latest versions, and may not even know a package exists. On RHEL and Fedora, DNF almost takes care of it by itself.
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 when it has expired (48 hours by default); the
--refresh option forces the refresh. This command shows the packages that have
a newer version available. An exit code of 100 means that updates
exist: it is normal.
On Debian and Ubuntu, get into the habit of running apt 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 … (or a
404 Not Found error during the download) that seems incomprehensible. On RHEL
and Fedora, this habit is not needed: dnf install checks the age of the
metadata itself.
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 dozens (96 in the test on Ubuntu 24.04; this
number varies with the state of the repositories).
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 four steps below go from the installation itself to the check that the command works, then to the package that provides it, and finally to the repository it comes from.
-
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. Unlike APT, where Enter confirms, DNF's[y/N]prompt cancels when you press Enter alone. -
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 -
Check where the package comes from: a package always comes from a repository, and by installing it you trust that repository. You might as well know which one.
Terminal window apt policy treeThe output starts with the installed version (
Installed) and the version offered by the repositories (Candidate). Below, a table lists the known versions: each one carries a priority, followed by the repositories that offer it with their address. The/var/lib/dpkg/statusline marks the version already installed on the machine.Terminal window dnf info treeThe
From repoline gives the repository the package was installed from, for examplebaseos. TheRepositoryline of an already installed package shows@System: it designates the machine itself, not a repository. It names a real repository only for a package that is not yet installed.
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, tested 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.
apt remove leaves the dependencies that are no longer needed: apt autoremove, covered in the guide on cleaning up, offers to remove them
afterwards.
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, by default, also removes the dependencies that are
no longer needed (the clean_requirements_on_remove setting). A dependency that
you had installed yourself by hand is not removed.
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 come back often at the start, and none comes from the
package itself. The first three are caused by an out-of-date list, an inexact
name or a forgotten sudo. The last two come from the dependencies or from the
name of the command. 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
- On Debian and Ubuntu,
apt updatebefore installing; DNF refreshes its metadata by itself when it has expired. 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.
apt policyanddnf infotell you where a package comes from; with DNF, readFrom reporather thanRepository, which shows@System.- 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)Result saved on this device. It will be sent to your account at the next sync. Sync now
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