Skip to content

Managing Programs in Linux: Installation, Update, and Removal

In Linux, software is distributed as packages, stored in official and third‑party repositories. The installation, updating, and removal of packages are managed by specialized tools — package managers.

The choice of manager depends on the distribution:

Distribution Package Manager Package Format
Debian 12/13, Ubuntu 22.04/24.04/26.04 (and derivatives) apt / apt-get, apt-cache .deb
CentOS 7 and earlier, BitrixOS yum .rpm
CentOS 8, CentOS Stream, AlmaLinux / Rocky Linux 8–10, RHEL 8+ dnf (successor to yum) .rpm

Note

In modern Ubuntu/Debian, it is preferable to use apt — a simplified and convenient interface that combines the functions of apt-get and apt-cache.
In RPM systems with dnf, the command syntax is almost identical to yum, and the yum command itself is kept there as an alias for dnf.

Note

Most commands require superuser privileges — use sudo.

  1. Updating the package list

    Before installing or updating, always refresh the local metadata cache:

    System Command
    Debian / Ubuntu sudo apt update
    CentOS 7 / BitrixOS sudo yum check-update
    AlmaLinux / Rocky Linux 8–10, CentOS 8 / Stream sudo dnf check-update (or sudo dnf makecache)

    Note

    apt update ≠ apt upgrade!
    update only updates lists,
    upgrade updates installed packages.

  2. Searching for packages

    If you don't know the exact name, search by keywords:

    System Command
    Debian / Ubuntu apt search keyword
    CentOS / RHEL (yum/dnf) yum search keyword
    dnf search keyword

    Example:

    apt search nginx
    
  3. Viewing package information

    Find the version, description, dependencies, and size before installation:

    System Command
    Debian / Ubuntu apt show package_name
    CentOS / RHEL yum info package_name
    dnf info package_name

    Example:

    apt show curl
    
  4. Installing packages

    Basic installation:

    Debian/Ubuntu

    sudo apt install package_name
    
    CentOS 7 / BitrixOS

    sudo yum install package_name
    

    AlmaLinux / Rocky Linux 8–10, CentOS 8 / Stream

    sudo dnf install package_name
    

    Installing multiple packages:

    sudo apt install nginx git htop
    

    Installing a specific version:

    First, check which versions are available in the enabled repositories, then specify the one you need.

    Debian/Ubuntu (the version is specified with =)

    apt list -a nginx
    sudo apt install nginx=<version>
    

    yum/dnf (the version is specified with a hyphen)

    yum --showduplicates list nginx    # CentOS 7
    dnf --showduplicates list nginx    # AlmaLinux / Rocky Linux, CentOS 8
    sudo dnf install nginx-<version>
    

    Note

    Version numbers depend on the distribution and the enabled repositories — use the values from the output of the commands above, not from examples found on the internet.

  5. Updating packages

    Update all installed packages to the latest versions:

    System Command
    Debian / Ubuntu sudo apt upgrade
    *or sudo apt full-upgrade — to handle dependencies with removal/replacement of packages*
    CentOS 7 / BitrixOS sudo yum update
    AlmaLinux / Rocky Linux 8–10, CentOS 8 / Stream sudo dnf upgrade
  6. Removing packages

    Remove a package while preserving configuration files:

    Debian/Ubuntu

    sudo apt remove package_name
    
    yum/dnf

    sudo yum remove package_name
    sudo dnf remove package_name
    

    Full removal (including configs):

    sudo apt purge package_name
    

    Automatic dependency cleanup

    Removes packages that were installed only as dependencies but are no longer required:

    Debian/Ubuntu

    sudo apt autoremove
    

    yum/dnf

    sudo yum autoremove    # CentOS 7
    sudo dnf autoremove    # AlmaLinux / Rocky Linux, CentOS 8
    

    Note

    The remove and update/upgrade commands by themselves do not remove all dependencies that are no longer needed. In dnf, the clean_requirements_on_remove=True option (enabled by default) removes dependencies installed together with the package being removed, but use autoremove for a full cleanup. In CentOS 7, yum does not remove dependencies by default. Always review the list of packages to be removed before confirming.

    Additionally: clearing the cache of downloaded packages

    sudo apt clean        # remove ALL .deb files from cache
    sudo apt autoclean    # remove ONLY outdated .deb files
    sudo yum clean all    # CentOS 7
    sudo dnf clean all    # AlmaLinux / Rocky Linux, CentOS 8
    

Information

Useful alternatives

Task Command
Check if a package is installed dpkg -l \| grep package_name (Debian)
rpm -q package_name (RPM)
See what files a package contains dpkg -L package_name
rpm -ql package_name
Find which package owns a file dpkg -S /path/to/file
rpm -qf /path/to/file
question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×