Linux Package Management Guide for Beginners¶
In Linux, we don't usually download .exe or .msi files from websites like we do in Windows. Instead, we use Package Managers. This guide will explain what they are and how to use them effectively.
๐ฆ What is a Package?¶
A Package is a compressed archive that contains all the files needed for a specific software to run. It includes: * The executable program. * Configuration files. * Information about what other software (dependencies) it needs to work.
๐ ๏ธ What is a Package Manager?¶
A Package Manager is a tool that automates the process of installing, upgrading, configuring, and removing software. It handles: 1. Downloading: Finding and downloading the package from a central server called a Repository. 2. Dependencies: Automatically installing any other software required by the package. 3. Integrity: Checking if the package is safe and hasn't been tampered with.
๐๏ธ Common Package Managers by Distribution¶
Different Linux families use different package managers:
| Linux Family | Distribution Examples | Package Manager | Package Format |
|---|---|---|---|
| Debian | Ubuntu, Debian, Mint | apt |
.deb |
| Red Hat | RHEL, CentOS, Fedora, Oracle Linux | yum / dnf |
.rpm |
| Alpine | Alpine Linux | apk |
.apk |
Tip
yum is being replaced by dnf in newer Red Hat-based systems, but the commands are almost identical.
๐ Basic Workflow: Installing Software¶
Before installing software, you should always update your local "index" of available packages. Think of this like refreshing a catalog.
1. Update Package Index¶
# Ubuntu/Debian
sudo apt update
# Red Hat/CentOS
sudo yum check-update
# Alpine
apk update
2. Search for a Package¶
If you're not sure of the exact name:
# Ubuntu/Debian
apt search tree
# Red Hat/CentOS
yum search tree
3. Install a Package¶
# Ubuntu/Debian
sudo apt install tree -y
# Red Hat/CentOS
sudo yum install tree -y
# Alpine
apk add tree
Note
The -y flag stands for "Yes," which automatically accepts the installation without asking for confirmation.
๐งน Removing Software¶
When you no longer need a program, you can remove it easily.
# Ubuntu/Debian
sudo apt remove tree
# Red Hat/CentOS
sudo yum remove tree
# Alpine
apk del tree
๐ Examples in Action¶
Using yum (Oracle Linux / CentOS)¶
[opc@new-k8s ~]$ sudo yum install -y tree
Complete!
[opc@new-k8s ~]$ tree
.
โโโ fruits.txt
โโโ myinfo
Using apt (Ubuntu)¶
root@ubuntu:/# apt update
root@ubuntu:/# apt install tree
root@ubuntu:/# tree --version
tree v2.0.2
๐ ๏ธ Advanced: Managing Repositories¶
Beyond basic installation, you often need to manage where software comes from. These locations are called Repositories.
๐ง Debian/Ubuntu (APT) Repositories¶
APT stores its configuration in two main places:
1. /etc/apt/sources.list: The primary file containing default repositories.
2. /etc/apt/sources.list.d/: A directory for adding third-party repositories. Each file must end in .list.
The Problem: Package Not Found If you try to install a tool like Docker or Ansible on a fresh system, you will likely see an error because they aren't in the default "catalog":
$ sudo apt install docker-ce ansible
Reading package lists... Done
E: Unable to locate package docker-ce
The Solution: Add the Repository
The easiest way is using the add-apt-repository command:
# Add a PPA (Personal Package Archive) - e.g., Latest Ansible for automation
sudo add-apt-repository ppa:ansible/ansible
# Add a standard remote repository - e.g., Docker for containerization
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
After: Successful Installation Once the repo is added and the index is updated, you can install the tools:
$ sudo apt update
$ sudo apt install docker-ce ansible -y
...
Setting up docker-ce (26.1.0-1~ubuntu.24.04~noble) ...
Setting up ansible (10.0.0-1ppa~noble) ...
Complete!
Important
Modern Ubuntu uses GPG keys in /usr/share/keyrings/ to verify package integrity. Always ensure you add the repository's key before updating.
๐ฉ Red Hat/CentOS (YUM/DNF) Repositories¶
The Problem: Package Not Found
Without the repo, dnf cannot find specialized software:
$ sudo dnf install docker-ce
Error: Unable to find a match: docker-ce
The Solution: Add the Repo File
Red Hat-based systems manage repositories using .repo files located in:
* /etc/yum.repos.d/
A typical repository file (/etc/yum.repos.d/docker-ce.repo) looks like this:
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
Adding a Repository (Command Line):
Alternatively, you can use dnf config-manager to add it automatically:
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
After: Successful Installation
Now dnf can see the packages from the new source:
$ sudo dnf makecache
$ sudo dnf install docker-ce -y
...
Installed:
docker-ce-3:26.1.0-1.el9.x86_64
containerd.io-1.6.31-3.1.el9.x86_64
Complete!
๐ Quick Comparison: Repository Commands¶
| Action | Debian/Ubuntu (apt) |
Red Hat/CentOS (yum/dnf) |
|---|---|---|
| Add Repository | add-apt-repository |
dnf config-manager --add-repo |
| Repo Location | /etc/apt/sources.list.d/ |
/etc/yum.repos.d/ |
| Clean Cache | apt clean |
dnf clean all |
| Build Cache | apt update |
dnf makecache |
๐ง Quick Quiz โ Package Management¶
Which package manager is used by Ubuntu?
๐ Want More Practice?¶
Test your knowledge with a full set of questions:
๐ Start Package Management Quiz (15 Questions)
๐ฌ DevopsPilot Weekly โ Learn DevOps, Cloud & Gen AI the simple way.
๐ Subscribe here