Script Valley
Linux Basics Complete Course: From Beginner to System Administrator
Module 6: Networking and Package ManagementLesson 6.2

Linux Package Management | apt and yum Tutorial

apt, apt-get, yum, dnf, install, update, upgrade, remove, search packages

Linux Package Management

Package management is how Linux systems install, update, configure, and remove software. Linux uses package managers to handle software dependencies automatically, ensuring that all required libraries are installed in the correct versions. Understanding apt and yum is essential Linux knowledge for anyone working with Ubuntu, Debian, CentOS, or Red Hat systems.

APT — Debian and Ubuntu Package Management

APT (Advanced Package Tool) is the package manager for Debian-based distributions including Ubuntu, Debian, and Linux Mint. It fetches packages from configured repositories, resolves dependencies, and handles installation and removal cleanly.

sudo apt update
sudo apt upgrade
sudo apt install nginx
sudo apt remove nginx
sudo apt purge nginx
sudo apt autoremove
sudo apt search nginx
apt show nginx

Always run sudo apt update before installing packages. It refreshes the local package index from repositories. The upgrade command then installs newer versions of all installed packages. The purge command removes the package and its configuration files, while remove keeps them.

Installing Specific Versions

You can install a specific version of a package by specifying the version number with an equals sign. The apt-cache policy command shows all available versions.

apt-cache policy nginx
sudo apt install nginx=1.18.0-6ubuntu14

YUM and DNF — Red Hat Package Management

YUM (Yellowdog Updater Modified) and its modern replacement DNF are the package managers for Red Hat Enterprise Linux, CentOS, AlmaLinux, Rocky Linux, and Fedora. The syntax is similar to apt.

sudo yum update
sudo yum install httpd
sudo yum remove httpd
sudo yum search httpd
yum info httpd
sudo dnf install nginx
sudo dnf update

Managing Package Repositories

On Ubuntu, package repositories are configured in /etc/apt/sources.list and files in /etc/apt/sources.list.d/. The add-apt-repository command adds third-party PPAs. On CentOS and Fedora, repositories are configured in /etc/yum.repos.d/.

cat /etc/apt/sources.list
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update && sudo apt install python3.11

Checking Installed Packages

The dpkg command lists all installed packages on Debian-based systems. The rpm command does the same on Red Hat-based systems.

dpkg --list
dpkg -l | grep nginx
rpm -qa
rpm -qa | grep httpd