π― What Youβll Learn
In this tutorial, youβll learn:
-
How to install applications in Linux π§©
-
The difference between
dnf
,yum
, andapt
π¦ -
When and why to use each one
-
Real-world analogies + useful examples
π§ What Is a Package Manager?
Think of a package manager like a Play Store for your Linux system.
-
You search, install, remove, or update software with simple commands.
-
It handles dependencies (extra files needed to make apps work).
-
It checks software repositories (online sources of trusted packages).
π¦ RHEL & RHCSA Use: dnf
(and yum
)
In RHEL 8 and above, the default package manager is:
dnf # Dandified YUM
β
dnf
is the modern replacement for yum
(Yellowdog Updater, Modified).
β
For RHCSA exam, focus on dnf
β itβs faster, smarter, and script-friendly.
π‘ Quick Comparison
Feature | dnf | yum | apt |
---|---|---|---|
Default in RHEL 8+ | β | β (deprecated) | β |
Used in Debian/Ubuntu | β | β | β |
Speed | Fast | Slower | Fast |
Dependency Handling | Better | Okay | Good |
Scripting | Stable APIs | Older style | Different syntax |
π§ Remember:
-
Use
dnf
oryum
on Red Hat-based distros: RHEL, CentOS, Fedora, Rocky, AlmaLinux -
Use
apt
on Debian-based distros: Ubuntu, Kali, Linux Mint
βοΈ 1. Install a Package
β
Using dnf
:
sudo dnf install httpd
This installs the Apache web server.
π Behind the scenes:
dnf
checks the repo, resolves dependencies, downloads everything, and installs it.
β
Using yum
(older systems):
sudo yum install httpd
Works the same way, but
yum
is now considered legacy.
β
Using apt
(Ubuntu/Debian):
sudo apt install apache2
Note: Package names may differ between
dnf
andapt
.
π 2. Update Installed Packages
RHEL (dnf):
sudo dnf update
Or:
sudo dnf upgrade
Debian/Ubuntu (apt):
sudo apt update # Refreshes repo index
sudo apt upgrade # Installs available updates
ποΈ 3. Remove (Uninstall) a Package
sudo dnf remove httpd
sudo apt remove apache2
You can also clean up unused dependencies:
sudo dnf autoremove
sudo apt autoremove
π 4. Search for a Package
sudo dnf search nginx
sudo apt search nginx
π§Ύ 5. List Installed Packages
dnf list installed
apt list --installed
π§ͺ 6. Check Info About a Package
dnf info nginx
apt show nginx
π₯ 7. Download a Package (but donβt install yet)
This is useful for offline installation.
dnf download nginx
π 8. Enable Repositories (Optional)
Sometimes, you need to enable Extra repositories for more packages.
Example for EPEL (Extra Packages for Enterprise Linux):
sudo dnf install epel-release
π§ Real-World Analogy
-
dnf
is like the Red Hat Software Center β optimized, official, enterprise-friendly -
yum
is the older software installer β like an old Play Store version -
apt
is the Ubuntu/Debian app store
Just like iOS and Android have different app stores, so do Red Hat and Ubuntu.
π§© Bonus: How to Add a Repository to RHEL
π― What Is a Repository?
A repository (repo) is like a warehouse of software packages. When you run dnf install
, your system downloads software from enabled repos.
β 1. Enable Official Red Hat Repositories
If your RHEL system is registered with Red Hat Subscription Manager (subscription-manager
), you can enable Red Hat-provided repos:
π Register System (if not already)
sudo subscription-manager register
Enter your Red Hat Customer Portal username & password.
π§Ύ Attach Subscription
sudo subscription-manager attach --auto
π¦ List Available Repos
sudo subscription-manager repos --list
β Enable Specific Repo
sudo subscription-manager repos --enable=rhel-8-for-x86_64-baseos-rpms
sudo subscription-manager repos --enable=rhel-8-for-x86_64-appstream-rpms
These two are the core repositories needed for RHCSA and general usage.
π§° 2. Add EPEL (Extra Packages for Enterprise Linux)
EPEL = A popular third-party repo from Fedora project. Contains packages not included in official Red Hat repos (like htop
, nginx
, etc).
β RHEL 8+:
sudo dnf install epel-release
Then verify:
dnf repolist
π§© 3. Add Custom or Local Repository Using .repo
File
You can create a custom .repo
file in /etc/yum.repos.d/
.
π Example:
Create a file:
sudo nano /etc/yum.repos.d/mytools.repo
Paste this sample content:
[mytools]
name=My Custom Tools Repo
baseurl=http://192.168.1.100/repos/mytools/
enabled=1
gpgcheck=0
Then run:
sudo dnf clean all
sudo dnf repolist
π―
baseurl
can also point to an FTP server, a local folder (file:///
), or mount.
π 4. GPG Key Setup (Recommended for Security)
π― What is GPG?
GPG stands for GNU Privacy Guard β it's a way to verify that the software you're installing hasnβt been tampered with.
π§ Simple Analogy:
Think of installing software like receiving a package in the mail.
-
The .rpm package is the box π¦
-
The GPG signature is the security seal or hologram π
-
The GPG key is what your system uses to check if the seal is real and not faked π΅οΈββοΈ
If the seal doesnβt match the key β β Donβt trust it!
β Why Use GPG Keys?
-
π‘ Protects against malware or tampered packages
-
β Ensures the package is really from the original trusted source
-
π Automatically checks every time you install/update packages
β How It Works (Behind the Scenes)
When GPG checking is enabled:
-
The system downloads a .rpm file.
-
It checks the fileβs digital signature.
-
It uses the GPG public key to verify the signature.
-
If the signature is valid β β Install proceeds.
-
If the signature is invalid or missing β β οΈ Error. Install is blocked.
To enable GPG check (verify package authenticity):
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
π Verify Enabled Repositories
dnf repolist
Full list (enabled + disabled):
dnf repolist all
π§ͺ Test Installation from Repo
Try installing a package from the new repo:
sudo dnf install htop
If the package is not found, check:
-
Repo is enabled
-
Base URL is reachable
-
Repo metadata is clean:
sudo dnf clean all
sudo dnf makecache
π§ Disable a Repo
Temporarily (on command):
sudo dnf install packagename --disablerepo=repo-id
Permanently (edit .repo
file):
enabled=0
β Summary / Key Takeaways
Task | dnf (RHEL) | apt (Ubuntu) |
---|---|---|
Install package |
|
|
Remove package |
|
|
Update system |
|
|
Search package |
|
|
Package info |
|
|
Task
Task | Command |
---|---|
Register system |
|
Enable RHEL repo |
|
Add EPEL |
|
Create custom repo | Edit |
List repos |
|
Clean cache |
|
π¬ Final Words
-
For RHCSA, focus on mastering
dnf
. -
Practice installing packages like
vim
,nginx
,httpd
, andnet-tools
. -
Understand how package managers simplify app installation, updates, and system maintenance.
-
RHEL uses
subscription-manager
for official repos -
.repo
files allow manual or internal repo setup -
Always verify with
dnf repolist
-
Use
gpgcheck=1
in production for security
π¦ Once you get comfortable with dnf
, managing software in Linux will feel as easy as installing apps on your phone.