Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Install and remove software on Linux

By updated

Improve this page

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.

Terminal window
sudo apt update
Expected output
Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease
Get:2 http://security.ubuntu.com/ubuntu noble-security InRelease
Reading package lists... Done

This command changes nothing on your system. It only downloads the up-to-date list of available packages and versions.

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:

Terminal window
apt search text editor

To show the details of a package you found:

Terminal window
apt show vim
Output (excerpt)
Package: vim
Version: 2:9.1.0016-1ubuntu7.20
Description: Vi IMproved - enhanced vi editor

Search 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.

  1. Start the installation with sudo (packages are installed in system directories that require administrator rights):

    Terminal window
    sudo apt install tree

    APT shows the list of packages that will be installed:

    Output on Ubuntu 24.04
    The following NEW packages will be installed:
    tree
    0 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.

  2. Check that the installation worked:

    Terminal window
    tree --version
    Output on Ubuntu 24.04
    tree v2.1.1 (c) 1996 - 2023 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro

    If the command prints a version number, the software is installed.

  3. Check which package provides a command (useful when the name differs):

    Terminal window
    dpkg -S "$(command -v tree)"
    Output
    tree: /usr/bin/tree
  4. 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 tree

    The 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/status line marks the version already installed on the machine.

Install several packages at once

You can install several packages in the same command, separated by spaces:

Terminal window
sudo apt install wget tree htop

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):

Terminal window
sudo apt remove tree

Complete removal (also deletes the configuration files):

Terminal window
sudo apt purge tree

Check: the command must no longer be available:

Terminal window
tree --version
Expected output
bash: tree: command not found

If 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:

Terminal window
dpkg -l | head -20

To check whether a given package is installed:

Terminal window
dpkg -l tree

How 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:

Terminal window
sudo apt reinstall tree

Troubleshooting

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.

SymptomLikely causeFix
E: Unable to locate packagePackage list out of datesudo apt update then try again
No match for argumentWrong package nameCheck 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 sudoAdd sudo in front of the command
Removal takes away too many packagesReverse dependenciesAnswer n, check the dependencies
Package installed but command not foundThe binary has another nameLook with dpkg -L name or rpm -ql name

Key points

  • On Debian and Ubuntu, apt update before installing; DNF refreshes its metadata by itself when it has expired.
  • apt install / dnf install handle dependencies automatically.
  • apt search / dnf search find the right package name: search in English.
  • apt remove keeps the configuration; apt purge deletes everything.
  • Always read the summary before confirming an installation or a removal.
  • apt policy and dnf info tell you where a package comes from; with DNF, read From repo rather than Repository, which shows @System.
  • Check with command --version that 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

6 questions
6 min
70% to pass

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