Bird
Raised Fist0
Linux CLIscripting~15 mins

yum/dnf (RHEL/CentOS) basics in Linux CLI - Deep Dive

Choose your learning style10 modes available
Overview - yum/dnf (RHEL/CentOS) basics
What is it?
yum and dnf are command-line tools used to manage software packages on RHEL and CentOS Linux systems. They help you install, update, and remove software easily by handling dependencies automatically. DNF is the newer version that replaces yum with improved performance and features. Both tools connect to online repositories to find and download software packages.
Why it matters
Without yum or dnf, installing or updating software on Linux would be slow and error-prone because you would have to manually find, download, and install each package and its dependencies. These tools save time and prevent mistakes by automating this process. They keep your system secure and up-to-date with minimal effort.
Where it fits
Before learning yum/dnf, you should understand basic Linux commands and file system structure. After mastering yum/dnf basics, you can learn advanced package management, repository configuration, and automation scripts for system maintenance.
Mental Model
Core Idea
yum and dnf are helpers that automatically fetch and manage software packages and their dependencies for you on RHEL/CentOS systems.
Think of it like...
Using yum or dnf is like having a personal shopper who knows exactly what you need and where to get it, so you don’t have to search for each item yourself.
┌─────────────┐       ┌───────────────┐       ┌───────────────┐
│ User issues │──────▶│ yum/dnf tool  │──────▶│ Online repos  │
│ command     │       │ fetches and   │       │ provide       │
│ (install,   │       │ installs      │       │ packages      │
│ update,     │       │ packages      │       │ and metadata  │
│ remove)     │       └───────────────┘       └───────────────┘
Build-Up - 7 Steps
1
FoundationUnderstanding Package Management Basics
🤔
Concept: Learn what software packages and dependencies are, and why managing them manually is hard.
Software on Linux is distributed as packages. Each package contains files and instructions to install a program. Many packages depend on others to work properly; these are called dependencies. Managing these manually means finding and installing each package and its dependencies in the right order, which is complicated and error-prone.
Result
You understand why tools like yum and dnf are needed to automate package management.
Knowing the complexity of manual package management explains why automated tools are essential for system stability and ease.
2
FoundationIntroducing yum and dnf Commands
🤔
Concept: Learn the basic commands to install, update, and remove software using yum or dnf.
To install a package: 'sudo yum install package-name' or 'sudo dnf install package-name'. To update all packages: 'sudo yum update' or 'sudo dnf update'. To remove a package: 'sudo yum remove package-name' or 'sudo dnf remove package-name'. These commands automatically handle dependencies and download packages from configured repositories.
Result
You can perform basic software management tasks on RHEL/CentOS systems.
Mastering these commands empowers you to control software on your system safely and efficiently.
3
IntermediateUnderstanding Repositories and Metadata
🤔
Concept: Learn how yum/dnf use repositories and metadata to find and verify packages.
Repositories are servers that store software packages and metadata describing them. yum/dnf read repository metadata to know what packages are available, their versions, and dependencies. You can list enabled repositories with 'yum repolist' or 'dnf repolist'. Repositories can be official or third-party, and you can add or disable them as needed.
Result
You understand where yum/dnf get software and how they know what to install.
Knowing about repositories helps you customize your software sources and troubleshoot package availability issues.
4
IntermediateUsing yum/dnf for Package Queries
🤔Before reading on: do you think 'yum list installed' shows all packages or only recently installed ones? Commit to your answer.
Concept: Learn commands to search for packages, list installed packages, and check package info.
To search for a package: 'yum search keyword' or 'dnf search keyword'. To list installed packages: 'yum list installed' or 'dnf list installed'. To get detailed info about a package: 'yum info package-name' or 'dnf info package-name'. These commands help you explore available software and your system's current state.
Result
You can find and inspect packages before installing or updating them.
Being able to query packages prevents mistakes and helps you make informed decisions about software management.
5
IntermediateHandling Package Groups and History
🤔Before reading on: do you think package groups install single packages or collections? Commit to your answer.
Concept: Learn how to install collections of packages as groups and how to review past yum/dnf actions.
Package groups are sets of related packages bundled for convenience, like 'Development Tools'. Install a group with 'yum groupinstall "Group Name"' or 'dnf groupinstall "Group Name"'. To see transaction history, use 'yum history' or 'dnf history' to review or undo past actions.
Result
You can install multiple related packages easily and track changes made by yum/dnf.
Using groups and history improves efficiency and safety when managing complex software setups.
6
AdvancedConfiguring yum/dnf and Repositories
🤔Before reading on: do you think repository configs are stored in a single file or multiple files? Commit to your answer.
Concept: Learn where yum/dnf configuration files are and how to add or modify repositories.
yum/dnf configs are in '/etc/yum.conf' and repository files are in '/etc/yum.repos.d/'. Each repo has a '.repo' file with settings like base URL and enabled status. You can add third-party repos by creating new '.repo' files or disable repos by setting 'enabled=0'. Configuring repos controls where packages come from and what updates are available.
Result
You can customize your package sources and control software updates.
Understanding configuration files lets you tailor your system’s software management to your needs and security policies.
7
ExpertDNF Internals and Performance Improvements
🤔Before reading on: do you think dnf uses the same backend as yum or a new one? Commit to your answer.
Concept: Learn how dnf improves on yum with a new backend, better dependency resolution, and faster performance.
DNF uses the 'libsolv' library for dependency solving, which is faster and more accurate than yum’s older method. It also uses 'hawkey' for package management and 'librepo' for downloading. These changes reduce memory use and speed up operations. DNF supports plugins and modularity better, making it more flexible for modern systems.
Result
You understand why dnf is preferred over yum in newer RHEL/CentOS versions.
Knowing dnf’s internals helps you appreciate its reliability and guides troubleshooting and optimization.
Under the Hood
yum and dnf work by reading repository metadata files that list available packages and their dependencies. When you request a package, they calculate all required dependencies using a dependency resolver. Then they download the packages from repository servers and install them in the correct order. DNF uses a modern dependency solver called libsolv for better accuracy and speed. Both tools keep a local database of installed packages to track system state.
Why designed this way?
Manual package management was error-prone and tedious, so yum was created to automate dependency handling and package installation. DNF was designed later to improve performance, modularity, and maintainability by using modern libraries and better algorithms. This design reduces bugs and speeds up package operations, meeting the needs of growing Linux ecosystems.
┌───────────────┐       ┌───────────────┐       ┌───────────────┐
│ User command  │──────▶│ yum/dnf tool  │──────▶│ Repository    │
│ (install etc) │       │ reads metadata│       │ servers       │
└───────────────┘       │ resolves deps│       └───────────────┘
                        │ downloads pkgs│
                        │ installs pkgs│
                        └───────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Does 'yum remove' delete only the named package or also its dependencies? Commit to your answer.
Common Belief:Running 'yum remove package' only deletes that package and leaves dependencies intact.
Tap to reveal reality
Reality:'yum remove' deletes the named package and any dependencies that are no longer needed (orphaned).
Why it matters:Not knowing this can cause accidental removal of important packages, breaking the system.
Quick: Do you think 'yum update' upgrades the OS kernel by default? Commit to your answer.
Common Belief:'yum update' always updates all packages including the kernel.
Tap to reveal reality
Reality:'yum update' updates all packages with available updates, but kernel updates depend on repository and configuration settings.
Why it matters:Assuming kernel always updates can cause unexpected reboots or missed security patches.
Quick: Is dnf just a renamed version of yum with no internal changes? Commit to your answer.
Common Belief:DNF is just yum with a new name and same internal workings.
Tap to reveal reality
Reality:DNF has a completely new backend with improved dependency solving and performance.
Why it matters:Misunderstanding this leads to ignoring dnf’s advantages and missing better system management.
Quick: Does disabling a repository in yum/dnf prevent all package installations from it? Commit to your answer.
Common Belief:Disabling a repo means no packages from it can ever be installed or updated.
Tap to reveal reality
Reality:Disabling a repo prevents it from being used by default, but packages already installed from it remain and can be updated if explicitly specified.
Why it matters:Assuming disabling removes all influence can cause confusion about package sources and updates.
Expert Zone
1
DNF’s use of libsolv allows it to handle complex dependency graphs and modular streams, which yum cannot do efficiently.
2
Transaction history in yum/dnf is stored and can be used to undo or redo package operations, which is critical for system recovery.
3
Repository metadata caching improves performance but can cause stale data issues if not refreshed regularly.
When NOT to use
yum/dnf are designed for RPM-based systems like RHEL and CentOS. For Debian-based systems, use apt. For containerized environments, package managers inside containers may be unnecessary or replaced by image layering tools.
Production Patterns
In production, yum/dnf are often used with automation tools like Ansible to manage packages across many servers. Repositories are carefully curated and mirrored internally for security and speed. Transaction history and rollback features are used to maintain system stability during updates.
Connections
apt (Debian/Ubuntu package manager)
Similar pattern: both automate package management but for different Linux families.
Understanding yum/dnf helps grasp apt’s role and differences, broadening Linux package management knowledge.
Dependency Injection (software design)
Both handle dependencies automatically to simplify complex systems.
Seeing package managers as dependency injectors clarifies how automation reduces manual errors in software setups.
Supply Chain Management (logistics)
Both manage sourcing, dependencies, and delivery of components efficiently.
Comparing package management to supply chains highlights the importance of reliable sources and dependency tracking.
Common Pitfalls
#1Trying to install a package without root privileges.
Wrong approach:yum install httpd
Correct approach:sudo yum install httpd
Root cause:Not understanding that package management requires administrative rights to modify system software.
#2Ignoring repository metadata updates causing stale package info.
Wrong approach:yum install package (without running 'yum makecache' or 'yum update')
Correct approach:yum makecache yum install package
Root cause:Not refreshing repository metadata leads to failed installs or outdated packages.
#3Removing a package without checking dependencies, causing system breakage.
Wrong approach:yum remove python3
Correct approach:yum remove python3 # Review dependencies carefully before confirming removal
Root cause:Not reviewing what else will be removed with the package.
Key Takeaways
yum and dnf automate software installation and updates by managing package dependencies on RHEL/CentOS systems.
They connect to repositories that store packages and metadata, enabling easy access to software.
Basic commands include install, update, remove, search, and info to control software safely.
DNF is the modern replacement for yum with better performance and dependency resolution.
Understanding repositories, configuration, and transaction history is key to effective package management.

Practice

(1/5)
1. What is the primary purpose of the yum or dnf command on RHEL/CentOS systems?
easy
A. To configure network settings
B. To monitor system hardware performance
C. To edit text files in the terminal
D. To manage software packages by installing, updating, or removing them

Solution

  1. Step 1: Understand the role of yum/dnf

    yum and dnf are package managers used to handle software packages on RHEL/CentOS.
  2. Step 2: Identify the correct function

    They allow users to install, update, and remove software easily.
  3. Final Answer:

    To manage software packages by installing, updating, or removing them -> Option D
  4. Quick Check:

    yum/dnf = software package management [OK]
Hint: yum/dnf commands control software packages [OK]
Common Mistakes:
  • Confusing yum/dnf with system monitoring tools
  • Thinking yum/dnf edits files or network settings
  • Mixing yum/dnf with text editors
2. Which of the following is the correct syntax to install a package named httpd using dnf with automatic yes to prompts?
easy
A. dnf install httpd y
B. dnf -y install httpd
C. dnf -y httpd install
D. dnf httpd install -y

Solution

  1. Step 1: Understand dnf command syntax

    The -y option should come immediately after dnf to apply to the entire command.
  2. Step 2: Check the order of arguments

    Correct syntax is dnf -y install httpd to install with automatic yes.
  3. Final Answer:

    dnf -y install httpd -> Option B
  4. Quick Check:

    dnf -y install package = correct syntax [OK]
Hint: Place -y right after dnf for automatic yes [OK]
Common Mistakes:
  • Putting -y after the package name
  • Mixing argument order causing syntax errors
  • Using incorrect command order
3. What will be the output of the command dnf list installed | grep bash on a system where bash is installed?
medium
A. A list of all packages except bash
B. An error saying 'bash not found'
C. A list line showing the bash package details
D. No output at all

Solution

  1. Step 1: Understand the command components

    dnf list installed lists all installed packages; piping to grep bash filters lines containing 'bash'.
  2. Step 2: Predict output if bash is installed

    Since bash is installed, the output will show the bash package line.
  3. Final Answer:

    A list line showing the bash package details -> Option C
  4. Quick Check:

    dnf list installed | grep bash = bash package line [OK]
Hint: grep filters output lines containing the keyword [OK]
Common Mistakes:
  • Expecting an error if package exists
  • Thinking grep excludes matching lines
  • Assuming no output means package installed
4. You run sudo yum install -y nginx but get an error: Could not find a valid baseurl for repo. What is the most likely cause?
medium
A. Network connection or repository configuration issue
B. The nginx package does not exist
C. You forgot to use sudo
D. The command syntax is incorrect

Solution

  1. Step 1: Analyze the error message

    The error 'Could not find a valid baseurl for repo' means yum/dnf cannot reach the repository URL.
  2. Step 2: Identify common causes

    This usually happens due to network issues or wrong repo configuration, not package absence or syntax errors.
  3. Final Answer:

    Network connection or repository configuration issue -> Option A
  4. Quick Check:

    Repo baseurl error = network or repo config problem [OK]
Hint: Check network and repo config if baseurl error appears [OK]
Common Mistakes:
  • Assuming package missing causes baseurl error
  • Ignoring need for network access
  • Blaming command syntax for repo errors
5. You want to automate updating all packages on a CentOS system without prompts. Which command should you use?
hard
A. sudo dnf update -y
B. sudo yum update
C. sudo dnf install -y
D. sudo yum remove -y

Solution

  1. Step 1: Identify the command to update all packages

    dnf update or yum update updates all installed packages.
  2. Step 2: Add automation to avoid prompts

    Adding -y automatically answers yes to prompts, enabling automation.
  3. Final Answer:

    sudo dnf update -y -> Option A
  4. Quick Check:

    dnf update -y = automated full update [OK]
Hint: Use -y with update to automate package upgrades [OK]
Common Mistakes:
  • Using install instead of update to upgrade packages
  • Forgetting sudo for permission
  • Using remove instead of update
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard