FA

Package Management in Linux

Complete Guide to Installing, Removing, and Updating Software

June 5, 2023  |  25 min read

Package Management is one of the most important skills in Linux. Packages contain software, libraries, and various tools that you can install, remove, update, and search for using a package manager. This article walks you step by step through the concepts and tools of package management across different Linux distributions in simple language.

Prerequisite: Familiarity with the terminal environment and basic commands is sufficient. All concepts are explained from scratch.

1. What is a Package and a Package Manager?

A package is an archived file containing executables, libraries, configuration files, and documentation for a piece of software. A package manager is a tool that manages these packages—it resolves dependencies, places files in the correct locations, and makes installation and removal easy.

In Linux, there are two main package manager families:

  • Debian-based: Use .deb packages and the apt tool (e.g., Ubuntu, Debian, Linux Mint).
  • Red Hat-based: Use .rpm packages and the yum or dnf tools (e.g., Fedora, RHEL, CentOS).
  • Arch-based: Use .pkg.tar.xz packages and the pacman tool (e.g., Arch Linux, Manjaro).

In addition, modern tools like Snap, Flatpak, and AppImage exist, allowing you to install software independently of the distribution.

2. Package Management with APT (Debian/Ubuntu)

APT (Advanced Package Tool) is the most popular package manager in Debian-based distributions. With APT, you can easily install software from the official repositories.

Updating the Package List

Before doing anything, update the list of available packages from the repositories:

sudo apt update

Upgrading Installed Packages

To upgrade all installed packages to their latest versions:

sudo apt upgrade

For a full system upgrade (including kernel and dependencies):

sudo apt full-upgrade

Installing a New Package

sudo apt install package_name

For example, to install the Vim editor:

sudo apt install vim

Removing a Package

sudo apt remove package_name

To remove it completely along with its configuration files:

sudo apt purge package_name

Searching for a Package

apt search keyword

Displaying Package Information

apt show package_name
Tip: The apt commands are designed for end users. If you need lower-level tools, use apt-get and apt-cache.

3. Package Management with DNF and YUM (Fedora/RHEL)

DNF (Dandified YUM) is the newer version of YUM and is used in Red Hat-based distributions. DNF commands are similar to APT.

Updating the Package List

In DNF, there is no separate update command, but to sync repositories:

sudo dnf makecache

Upgrading Packages

sudo dnf upgrade

Installing a New Package

sudo dnf install package_name

Removing a Package

sudo dnf remove package_name

Searching and Package Information

dnf search keyword
dnf info package_name

Software Groups

In DNF, you can install software groups (e.g., the "Development Tools" group):

sudo dnf groupinstall "Development Tools"
Difference between YUM and DNF: DNF is faster, lighter, and has better dependency handling. If you're using older distributions, YUM may still be available.

4. Package Management with Pacman (Arch Linux)

Pacman is the fast and powerful package manager of Arch Linux. Its commands are somewhat different but very efficient.

Syncing Repositories and System Upgrade

sudo pacman -Syu

This command syncs repositories and updates all packages.

Installing a New Package

sudo pacman -S package_name

Removing a Package

sudo pacman -R package_name

To remove the package along with unused dependencies:

sudo pacman -Rs package_name

Searching for a Package

pacman -Ss keyword

Displaying Package Information

pacman -Qi package_name

5. Modern Tools: Snap, Flatpak, and AppImage

These tools deliver software independently of the distribution, bundling their dependencies along with them.

Snap

Snap is developed by Canonical (the maker of Ubuntu). Installing with Snap:

sudo snap install package_name

Flatpak

Flatpak is a platform-independent software distribution system supported by many distributions.

flatpak install flathub package_name

AppImage

AppImage is a single executable file that runs without installation. Just download it and make it executable:

chmod +x appimage-file.AppImage
./appimage-file.AppImage

6. Software Repositories

A repository is a collection of software packages that the package manager uses. Adding new repositories allows you to install more software.

In Debian/Ubuntu, repositories are defined in /etc/apt/sources.list. To add a new repository:

sudo add-apt-repository ppa:repository-name
sudo apt update

7. Managing Individual Packages with dpkg and rpm

Sometimes you need to install a .deb or .rpm package directly (without a repository).

dpkg (for .deb packages)

sudo dpkg -i package.deb

If you encounter dependency errors, use apt to fix them:

sudo apt install -f

rpm (for .rpm packages)

sudo rpm -ivh package.rpm
Warning: Installing .deb or .rpm packages directly may not resolve dependencies. It is best to use your distribution's primary package manager whenever possible.

8. Practical Examples

Example 1: Installing a Complete Set of Development Tools

# Debian/Ubuntu
sudo apt install build-essential git curl wget vim

# Fedora/RHEL
sudo dnf install @development-tools git curl wget vim

# Arch
sudo pacman -S base-devel git curl wget vim

Example 2: Finding and Installing a Specific Library

# Search for libxml2 library
apt search libxml2
# Install
sudo apt install libxml2-dev

Example 3: Removing Unused Packages (Cleanup)

# Debian/Ubuntu - remove unnecessary packages
sudo apt autoremove

# Fedora/RHEL
sudo dnf autoremove

# Arch
sudo pacman -Rns $(pacman -Qdtq)

9. Package Manager Command Comparison

OperationAPT (Debian)DNF (Fedora)Pacman (Arch)
Install packageapt installdnf installpacman -S
Remove packageapt removednf removepacman -R
Updateapt update && apt upgradednf upgradepacman -Syu
Searchapt searchdnf searchpacman -Ss
Package infoapt showdnf infopacman -Qi
Remove unused dependenciesapt autoremovednf autoremovepacman -Rns $(pacman -Qdtq)

Conclusion and Next Steps

In this article, you learned the concepts and tools of package management in Linux. You can now easily install, remove, and update the software you need. To go further:

  • Learn about different repositories and how to add them.
  • Try Snap and Flatpak for installing modern applications.
  • Explore advanced commands like aptitude or yumex (graphical version).
  • Read «The Linux Command Line» (available at Linux Library) for a deeper understanding.
Remember: Package management is one of the pillars of Linux. With practice, you will master it with ease.