EP9: Installing Applications in Linux (dnf vs yum vs apt)

🎯 What You’ll Learn

In this tutorial, you’ll learn:

  • How to install applications in Linux 🧩

  • The difference between dnf, yum, and apt πŸ“¦

  • 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 or yum 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 and apt.


πŸ” 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.


🎯 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:

  1. The system downloads a .rpm file.

  2. It checks the file’s digital signature.

  3. It uses the GPG public key to verify the signature.

  4. If the signature is valid β†’ βœ… Install proceeds.

  5. 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

dnf install name

apt install name

Remove package

dnf remove name

apt remove name

Update system

dnf update

apt update && apt upgrade

Search package

dnf search name

apt search name

Package info

dnf info name

apt show name

Task

Task

Command

Register system

subscription-manager register

Enable RHEL repo

subscription-manager repos --enable=...

Add EPEL

dnf install epel-release

Create custom repo

Edit /etc/yum.repos.d/custom.repo

List repos

dnf repolist

Clean cache

dnf clean all && dnf makecache


🎬 Final Words

  • For RHCSA, focus on mastering dnf.

  • Practice installing packages like vim, nginx, httpd, and net-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.

Updated on