RHCSA Training: Package Management with rpm and yum/dnf
This guide consolidates the core concepts and practical skills for managing software packages on Red Hat Enterprise Linux (RHEL) using both the low-level rpm and high-level yum (or dnf) tools.
Part 1: Core Concepts – rpm vs. yum
Objective: To master the installation, removal, querying, and management of software packages on Red Hat Enterprise Linux (RHEL) using both low-level (rpm) and high-level (yum/dnf) tools.
Key Knowledge Areas:
- The concept of a software package and dependency resolution.
- Using
rpmfor direct package manipulation and queries. - Using
yum(and its successor,dnf) for repository-based package management. - Understanding repositories and their configuration.
- Performing system updates.
1. Core Concepts: What is a Package?
Think of a Linux software package as a meticulously organized box delivered to your house.
- The Application: The main item you ordered (e.g., a text editor like
nano). - Metadata: The packing slip that tells the system:
- The package name and version.
- What other “boxes” (libraries or programs) are required for it to work (dependencies).
- Where to place the files on the system.
- Scripts to run after installation or removal.
- The Package File: On RHEL systems, these “boxes” have the file extension
.rpm(Red Hat Package Manager).
A Package Manager is the tool that opens the box, reads the slip, puts everything in the right place, and handles the paperwork.
2. The Low-Level Tool: rpm
The rpm command is the fundamental tool for handling .rpm files directly. It is powerful but has a critical limitation.
Key Limitation: rpm does not automatically resolve dependencies. If you try to install a package that requires another package, rpm will fail until you manually find and install all required dependencies first. This can lead to a frustrating “dependency hell.”
Essential rpm Commands for RHCSA
| Command | Description | Use Case & Example |
|---|---|---|
| Install | Installs a package from a local .rpm file. | sudo rpm -ivh nano-2.9.8-1.el8.x86_64.rpm-i: install-v: verbose-h: show progress hash marks |
| Upgrade | Upgrades a package if installed; installs it if not. | sudo rpm -Uvh nano-2.9.8-1.el8.x86_64.rpm |
| Erase/Remove | Removes an installed package. | sudo rpm -e nano |
| Query | Checks if a package is installed. | rpm -q nano |
| Query Info | Displays detailed package information. | rpm -qi nano |
| Query List | Lists all files installed by a package. (Crucial for troubleshooting) | rpm -ql nano |
| Verify | Verifies the integrity of package files. Checks for changes, deletions, or permission modifications. | rpm -V nano |
Exam Tip:
- Use
rpmwhen you are given a specific.rpmfile to install or when you need to query/verify what is installed on the system. - For most other tasks, you will use
yum.
3. The High-Level Tool: yum (and dnf)
To solve the dependency problem, Red Hat introduced yum (Yellowdog Updater, Modified). yum is a high-level wrapper around rpm that works with online repositories.
Key Advantage:
yumautomatically resolves, downloads, and installs all dependencies for you.
A Note on yum vs. dnf:
dnfis the next-generation version ofyum. It is the default package manager in RHEL 8 and 9.- For the purposes of the RHCSA exam,
yumanddnfare functionally equivalent. The commands are the same (e.g.,yum installworks, but it’s actually a link todnf). You can use either command.
Essential yum/dnf Commands for RHCSA
| Command | Description | Example |
|---|---|---|
| Install | Installs a package and its dependencies from a repository. | sudo yum install wget |
| Remove | Removes a package and any dependencies that are no longer needed. | sudo yum remove wget |
| Update | Updates all system packages to their latest versions. (A critical task!) | sudo yum update |
| Update (specific) | Updates a single package. | sudo yum update nano |
| Search | Searches repository metadata for a package. | yum search "text editor" |
| List Installed | Checks if a specific package is installed. | yum list installed wget |
| Info | Shows detailed information about a package (from the repository). | yum info wget |
| Provides | Finds which package provides a specific file. (Extremely useful!) | yum provides /etc/passwd |
| History | Views a log of past yum transactions. Allows for undo/rollback. | sudo yum historysudo yum history undo 15 |
4. Understanding Repositories
Repositories (“repos”) are centralized online storage locations that hold thousands of .rpm packages and their metadata.
- Official Repos: RHEL uses official Red Hat repositories (BaseOS, AppStream) that are enabled by subscription.
- Repo Configuration: Repository definitions are stored as
.repofiles in the/etc/yum.repos.d/directory. Each file tellsyumthe repository’s name, base URL, and whether it is enabled. - GPG Keys: Repositories are often signed with GPG keys for security. The system verifies package integrity using these keys.
Key Repository Command:
yum repolist all
- Lists all configured repositories (both enabled and disabled).
5. When to Use rpm vs. yum/dnf
| Scenario | Recommended Tool | Reason |
|---|---|---|
Installing from a downloaded .rpm file | rpm -ivh | Direct file manipulation. |
| Installing software by name from the internet | yum install | Automatic dependency resolution. |
| Checking which files belong to a package | rpm -ql | Fast, low-level query. |
| Updating the entire system | yum update | Safely handles all dependencies. |
| Working on a system with no internet access | rpm | You must use locally stored packages. |
| Deep troubleshooting (e.g., verifying file integrity) | rpm -V | Direct access to the package database. |
2. Using yum for Package Discovery and Installation
Objective: To demonstrate the practical use of yum for searching, inspecting, and installing software packages, which is a critical skill for the RHCSA exam.
Key Skills Demonstrated:
- Accessing command-line help.
- Searching repository packages with
yum search. - Inspecting package details with
yum info. - Installing packages with
yum install.
Demo Walkthrough & Expanded Explanation
Step 1: Accessing the Terminal
All package management in a server environment is done via the command line. The Terminal is your primary interface.
- Action: Open the Terminal via the Activities menu or use the keyboard shortcut Ctrl + Alt + T.
Step 2: Understanding yum --help
Before using any command, knowing how to access its built-in help is a fundamental sysadmin skill.
- Command:bashyum –help
- Output & Explanation: The output is a quick reference guide. For the RHCSA, you should be familiar with these common options:
install: Installs a package and its dependencies.remove: Removes a package and any now-unneeded dependencies.update: Updates all packages or a specified one.search: Searches package names and descriptions for a keyword.info: Displays detailed information about a package.provides: Finds which package owns a specific file.list: Lists packages based on criteria (e.g.,list installed).
Exam Tip: If you forget a specific
yumoption during the exam,--helpis your fastest and most reliable resource.
Step 3: Searching for Packages with yum search
You often know the function you need but not the exact package name. yum search is your tool for discovery.
yum search nano
- Output & Explanation: The search looks through package names and descriptions. The key part of the output is:textName Exactly Matched: nano nano.x86_64 : A small text editorThis confirms the package exists and is named
nano. - Testing for Non-Existent Packages:bashyum search helloOutput:
No matches found.
Explanation: This is a crucial troubleshooting step. If a package isn’t found, it means:- The package name is incorrect.
- The required repository is not enabled or configured.
- The package simply doesn’t exist in your current repos.
Step 4: Inspecting Packages with yum info
Always inspect a package before installation. This is a best practice to avoid installing the wrong software.
yum info nano
- Output & Explanation: The information provided is vital for system management:
- Name: The exact package name (
nano). - Version & Release: The specific software version (
5.6.1). Critical for troubleshooting and compliance. - Architecture: The CPU architecture (
x86_64). - Size: The download and install size (
2.7 M). Important for systems with limited resources. - Repository: Which repo it comes from (
appstream). Helps verify the source is trusted. - Description: A detailed summary of the package’s purpose.
- Name: The exact package name (
Exam Tip: Use
yum infoto confirm you are about to install the correct package and to note its version.
Step 5: Installing Packages with yum install
This is the final step where the software is actually deployed to the system.
yum install nano
- Output & Explanation (in the demo):textPackage nano is already installed. Dependencies resolved. Nothing to do. Complete!Explanation: This demonstrates that
yumis intelligent. It checks the local database first and will not reinstall a package unnecessarily. - What a Real Installation Looks Like:
Ifnanowere not installed,yumwould:- List the package(s) to be installed.
- List all dependencies that will also be installed.
- Show the total transaction size and ask for confirmation:
Is this ok [y/N]: - You must type
yand press Enter to proceed. The installation will then run automatically.
Key Takeaways for the RHCSA Exam
- The Standard Workflow: Your process for installing an unknown package should be: Search -> Info -> Install.
yumHandles Dependencies Automatically: Unlikerpm, you do not need to manually find and install dependencies.yumresolves, downloads, and installs them all.- Always Confirm: The
yum installcommand will always prompt you before making changes. This is your last chance to abort if you see unexpected packages. - Know Why a Package Might Not Be Found: If
yum searchreturns nothing, you should be able to diagnose the potential causes (wrong name, missing repo).
By mastering this yum workflow, you ensure that you can efficiently and correctly manage software on a RHEL system, a core competency for the RHCSA exam.
3. Mastering the rpm Command
Objective: To demonstrate the practical use of the low-level rpm command for querying, verifying, and installing software packages. This is a critical skill for the RHCSA exam, especially for scenarios involving offline packages and deep system inspection.
Key Skills Demonstrated:
- Querying package installation status.
- Retrieving detailed package information.
- Listing files owned by a package.
- Verifying package integrity.
- Identifying the package that owns a specific file.
- Understanding the manual installation process and its limitations.
Demo Walkthrough & Expanded Explanation
Step 1: Accessing rpm Help
The rpm command is extensive. Knowing how to access its help is the first step to using it effectively.
- Command:bashrpm –help
- Key Flags for RHCSA: From the output, focus on these essential options:
-q, --query: The foundation for all query operations.-i: Display package information (used with-q).-l: List files in a package (used with-q).-f, --file: Query the package that owns a file.-V, --verify: Verify the integrity of package files.-i, --install: Install a package.-U, --upgrade: Upgrade a package.-e, --erase: Remove (erase) a package.
Exam Tip:
rpm --helpgives a concise overview. For exhaustive detail, use the man page:man rpm.
Step 2: Querying Package Installation (rpm -q)
This is the most basic check to see if a package is installed.
rpm -q nano
- Output (if installed):
nano-5.6.1-7.el9.x86_64- Breakdown:
nano(package name),5.6.1(version),7.el9(release for RHEL 9),x86_64(architecture).
- Breakdown:
- Output (if not installed):
package nano is not installed
Step 3: Getting Detailed Package Information (rpm -qi)
This provides a “birth certificate” for an installed package, which is invaluable for auditing and troubleshooting.
rpm -qi nano
- Key Information in Output:
- Name, Version, Release: Precisely identifies the software build.
- Architecture: Confirms it’s built for your system (e.g., x86_64).
- Install Date: Tells you when the package was installed.
- Group: Categorizes the software (e.g.,
Applications/Editors). - Signature: Crucially important. The
RSA/SHA256signature andKey IDverify that the package is a trusted, unaltered binary from Red Hat. This ensures security and integrity. - Description: Confirms the package’s purpose.
Step 4: Listing Package Files (rpm -ql)
This answers the question: “What files did this package actually put on my system?”
rpm -ql nano
- Output & Explanation: You will see a list of every file installed by
nano, including:- Binaries:
/usr/bin/nano - Configuration Files:
/etc/nanorc - Documentation:
/usr/share/doc/nano/..., man pages.
- Binaries:
- Practical Use Case: If you find a strange file and want to know what software it belongs to, you can cross-reference it with this list. Conversely, if you know a configuration file was modified, you can verify its integrity (see next step).
Step 5: Verifying Package Integrity (rpm -V)
This is a powerful troubleshooting command that checks if files from an installed package have been changed from their original state.
rpm -V nano
- Output & Explanation:
- No Output: This is good! It means all files are unchanged.
- If Output Appears: It lists files that have been modified, along with a flag indicating what changed. For example:
S– File size differsM– Mode (permissions) differ5– MD5 checksum differs (the content was modified)U– User ownership differsG– Group ownership differsmissing– The file is missing.
Exam Scenario: You are told a critical application is failing. Using
rpm -V [package-name]can quickly tell you if its core binaries or config files have been accidentally altered or deleted.
Step 6: Identifying the Package Owning a File (rpm -qf)
This is the reverse of rpm -ql. It answers: “Which package does this file belong to?”
rpm -qf /usr/bin/nano
- Output:
nano-5.6.1-7.el9.x86_64 - Practical Use Case: You find a command (
/usr/bin/wget) and want to install the package that provides it.rpm -qftells you the package name iswget. You can then install it withyum install wget.
Step 7: Installing a Package with rpm (rpm -ivh)
This demonstrates the manual installation process and its critical caveat.
sudo rpm -ivh nano-5.6.1-7.el9.x86_64.rpm
- The Critical Limitation (Dependency Hell): If
nanorequired a library calledlibmagic, the command would fail with an error like:texterror: Failed dependencies: libmagic.so.1()(64bit) is needed by nano-5.6.1-7.el9.x86_64You would then have to manually find thelibmagicpackage, install it, and repeat for its dependencies—a tedious and error-prone process.
Key Takeaways for the RHCSA Exam
rpmis for Inspection and Offline Installs: Its primary strength is querying the package database (-q) and verifying the system (-V,-qf). Use it for installation (-i) only when you have a local.rpmfile and are prepared to handle dependencies manually.yum/dnfis for Installation: For almost all installation tasks, useyum install. It automatically resolves dependencies from repositories.- The Verification Workflow:
rpm -Vis a powerful, often-overlooked tool. Know how to use it to diagnose system issues. - Know the Relationship:
yumis a high-level tool that usesrpmunderneath. Whenyum installsa package, it ultimately callsrpmto perform the installation after resolving dependencies.
By mastering these rpm commands, you demonstrate a deep understanding of how the RHEL package management system works, which is essential for passing the RHCSA exam and for effective system administration.
4. System Updates and Upgrade Management with yum
Objective: To demonstrate the practical use of yum for checking, applying, and auditing system updates. Keeping a system updated is a fundamental administrative task and is critical for the RHCSA exam.
Key Skills Demonstrated:
- Checking for available updates.
- Performing full system updates.
- Updating specific packages.
- Applying security-specific updates.
- Reviewing update history for auditing and troubleshooting.
Demo Walkthrough & Expanded Explanation
**Step 1: Checking for Available Updates (yum check-update)
This is a “dry run” that scans all configured repositories to see what package updates are available without making any changes to the system.
sudo yum check-update
- Output & Explanation:
- If updates are available: It will list the packages with their current and available versions (e.g.,
kernel-5.14.0-284.el9.x86_64->kernel-5.14.0-305.el9.x86_64). - If no updates are available: The command returns to the prompt with no output. This is the expected behavior for “no news is good news” in this context.
- Exit Codes: This command has specific exit codes useful for scripting:
0for no updates,100for updates available, and other codes for errors.
- If updates are available: It will list the packages with their current and available versions (e.g.,
Exam Tip: Use
yum check-updateto quickly assess the update state of a system without committing to an installation.
**Step 2: Performing a Full System Update (yum update -y)
This is the primary command for keeping a RHEL system current. It resolves dependencies, downloads all available updates, and installs them.
sudo yum update -y
- Breakdown of the Command:
update: The action to upgrade all installed packages to their latest available versions.-y: The “yes” flag. This automatically confirms the transaction prompt. Use with caution in production, but it’s essential for the exam to avoid manual input.
- What Happens:
yumcalculates the transaction: which packages will be updated, installed, or obsoleted.- It shows a summary and, without the
-yflag, asksIs this ok [y/N]:. - After confirmation, it downloads and installs all packages.
- Critical Point: A kernel update will require a system reboot to activate.
Exam Tip: If an exam task says “update the system,”
sudo yum update -yis the command to use. Be prepared that a kernel update might be part of it.
**Step 3: Upgrading the System (yum upgrade -y)
In modern RHEL (versions 7+), yum update and yum upgrade are functionally identical. Historically, upgrade was more aggressive about removing obsolete packages. For the RHCSA, you can treat them as the same.
sudo yum upgrade -y
- Practical Advice: The Red Hat documentation often recommends using
yum update. For the exam, if the task says “upgrade,” usingupgradeis safe, butupdatewill achieve the same result.
**Step 4: Updating a Specific Package (yum update <package_name>)
You often need to update a single application without updating the entire system.
sudo yum update bash
- Output & Explanation: If the package is already the latest version, you will see
Nothing to do. Complete!. If an update is available,yumwill perform the update forbashand only its dependencies, not every package on the system. - Use Case: This is useful for applying a specific bug fix or security patch for a single service.
**Step 5: Applying Security Updates (yum update --security)
This is a critical command for maintaining system security. It filters available updates to install only those that fix security vulnerabilities.
sudo yum update –security
- Prerequisite: This requires your system to be subscribed to the official Red Hat repositories, as they provide the metadata that classifies an update as a security fix.
- Exam Relevance: A task might ask you to “apply all available security patches.” This is the command to use.
**Step 6: Reviewing Update History (yum history)
This is your system’s “flight recorder.” It provides a complete audit trail of all yum transactions, which is invaluable for troubleshooting.
sudo yum history
- Output Interpretation: The history list shows:
- ID: A unique transaction number.
- Command: The exact command that was run (e.g.,
update,install nano). - Date and Time: When the action occurred.
- Action(s): What was done (Installed, Updated, Erased, etc.).
- Altered: The number of packages affected.
- Powerful Follow-up Commands:
sudo yum history info <ID>: Shows detailed information about a specific transaction, including all packages that were changed.sudo yum history undo <ID>: This is a lifesaver. It attempts to reverse the transaction with the given ID. For example, if an update broke an application, you canundoit to revert to the previous state.
Exam Tip: If you make a mistake during the exam (e.g., remove the wrong package),
yum historyandyum history undoare your best friends for recovery.
Key Takeaways for the RHCSA Exam
- Know the Core Update Command:
sudo yum update -yis the workhorse for updating the entire system. - Understand
check-updatevs.update: Use the first to see what’s available; use the second to actually perform the update. - Specific Package Updates: You can update a single package by naming it (e.g.,
yum update kernel). - Security is a Priority: Know how to apply only security-related patches using
yum update --security. - Audit and Rollback:
yum historyis not just for logging; it’s a powerful troubleshooting and recovery tool. You must be comfortable using it to inspect past actions and undo them if necessary.
5. Package Lifecycle Management with yum
Objective: To demonstrate the complete lifecycle of a software package using yum, from installation and verification to removal. This is a fundamental, hands-on skill required for the RHCSA exam.
Key Skills Demonstrated:
- Installing a package and its dependencies with
yum install. - Verifying installation using both
rpmandyum history. - Removing a package cleanly with
yum remove. - Confirming package removal.
Demo Walkthrough & Expanded Explanation
Step 1: Installing a Package (yum install)
The yum install command is the standard method for adding software from configured repositories. Its key advantage is automatic dependency resolution.
sudo yum install httpd
- What Happens & What to Observe:
- Dependency Resolution:
yumcalculates thathttpdrequires other packages to function. It doesn’t just install one package; it installs 11 in this case. - Transaction Summary: Before doing anything,
yumpresents a summary:- Packages to Install: Lists the main package and all dependencies.
- Total Download Size: Shows the network bandwidth required.
- Total Installed Size: Shows the disk space that will be used.
- User Confirmation: The prompt
Is this ok [y/N]:is a critical safety check. You must typeyand press Enter to proceed. - Completion: The
Complete!message indicates a successful installation.
- Dependency Resolution:
Exam Tip: Always read the transaction summary. It ensures you are not accidentally installing unwanted or conflicting packages.
Step 2: Verifying Installation
After any installation or removal, verification is a crucial step.
Method 1: rpm -q (Direct Query): rpm -q httpd
Method 2: yum history (Audit Trail): sudo yum history
- Output Interpretation: You look for the transaction with the action
Installand the commandinstall httpd. - Why it’s Powerful: This provides an audit log. You can see the transaction ID (e.g.,
ID 2), which allows you to investigate further or even undo the action.
Step 3: Removing a Package (yum remove)
The yum remove command cleanly uninstalls a package and any dependencies that are no longer needed by other software.
sudo yum remove httpd
- What Happens & What to Observe:
- Transaction Summary:
yumshows the packages that will be removed. Notice they are often highlighted in red, providing a clear visual warning. - User Confirmation: Again, you must confirm with
y. This prevents accidental removal of critical software. - Cleanup:
yumintelligently removes the specified package and any dependencies that were installed with it and are not required by other packages. - Completion: The
Complete!message confirms successful removal.
- Transaction Summary:
Step 4: Verifying Removal
The final step is to confirm the package is truly gone.
rpm -q httpd
- Output:
package httpd is not installed - Explanation: This is the definitive confirmation that the package has been uninstalled from the system.
Key Takeaways for the RHCSA Exam
- The Standard Lifecycle Workflow is: Install -> Verify -> Remove -> Verify.
yumhandles dependencies automatically in both installation and removal. This is the primary reason to use it overrpmfor these tasks.- Always confirm the transaction. The
Is this ok [y/N]prompt is your last chance to abort. On the exam, you must typeyto proceed. - Verification is not optional. Use
rpm -qfor a quick check andyum historyfor a detailed audit log. The exam may ask you to verify your work, and this is how you do it. yum historyis your safety net. If you accidentally remove the wrong package during the exam, you can usesudo yum history undo <ID>to revert the transaction, where<ID>is the transaction number from theyum historylist.
6. Manual Package Management with rpm
Objective: To demonstrate the process and, more importantly, the practical limitations of using the low-level rpm command for package installation. This highlights why yum/dnf is the preferred tool and clarifies the exam expectations.
Key Skills Demonstrated:
- Downloading a local
.rpmfile usingdnf download. - Attempting installation with
rpm -ivh. - Understanding and identifying dependency errors.
- Resolving the situation using the correct tool (
yum install).
Demo Walkthrough & Expanded Explanation
**Step 1: Downloading the Package File (dnf download)
Since rpm works with local files, the first step is to acquire the .rpm file.
dnf download httpd
- Output & Explanation: This command fetches the
httpd-2.4.62-4.el9.x86_64.rpmfile from the enabled repositories and places it in your current working directory. It does not install the package. - Verification:bashlsThe file will be listed, often highlighted in red to indicate it’s an archive/package file.
**Step 2: The Installation Attempt (rpm -ivh)
This step demonstrates the core weakness of using rpm for installation.
sudo rpm -ivh httpd-2.4.62-4.el9.x86_64.rpm
- Breakdown of Flags:
-i: Install-v: Verbose (shows details)-h: Print hash marks (#####) as a progress bar.
- The Inevitable Outcome: Dependency Failures.
- Output: You will see errors like:texterror: Failed dependencies: httpd-core = 2.4.62-4.el9 is needed by httpd-2.4.62-4.el9.x86_64 system-logos-httpd is needed by httpd-2.4.62-4.el9.x86_64
- Explanation: The
httpdpackage is a meta-package that relies on other packages (likehttpd-core) to function. Therpmcommand sees that these required packages are not installed and aborts the entire operation. It will not proceed until you manually find, download, and install every single dependency, which can lead to a “dependency hell.”
**Step 3: The Correct Solution (yum install)
The demo correctly pivots to using the high-level tool to solve the problem rpm cannot.
sudo yum install httpd
- Why This Works:
yumdoes not rely on a local file. It:- Analyzes the dependency tree for the
httpdpackage. - Calculates all required packages.
- Downloads everything needed from the repositories.
- Uses
rpminternally to install all components in the correct order.
- Analyzes the dependency tree for the
- Exam Relevance: This is the standard, correct method for installing software from repositories.
**Step 4: Cleaning Up the Local File
After the installation is complete, the local .rpm file is no longer needed.
rm httpd-2.4.62-4.el9.x86_64.rpm
- Verification: Use
lsto confirm the file has been deleted.
Critical Analysis: Key Takeaways for the RHCSA Exam
rpm -ivhis for Local Files, Not Package Names: You cannot runrpm -ivh httpd. You must have the local.rpmfile first. Usednf downloadto get it.rpmDoes Not Resolve Dependencies: This is the single most important point. Therpmcommand is a low-level tool that installs only what you tell it to install. It will fail if any prerequisites are missing.yum/dnfis the Solution to Dependency Hell: The primary role ofyumis to be a dependency resolver. It finds and installs all required packages automatically.- When to Use
rpmfor Installation on the Exam:- Only when explicitly instructed to install from a specific, provided
.rpmfile path (e.g.,Install the package from /tmp/mypackage.rpm). - In such a case, you must be prepared for dependency errors. The exam question might be testing your ability to resolve them manually or your understanding that the failure is due to dependencies.
- Only when explicitly instructed to install from a specific, provided
- The Standard Workflow is
yum install: For 99% of tasks, if you are asked to “install a package,” the intended method isyum install [package_name].
Summary: rpm vs. yum for Installation
| Scenario | Command | Handles Dependencies? | Use Case |
|---|---|---|---|
| Install from repositories | sudo yum install httpd | Yes | Default, recommended method |
Install a local .rpm file | sudo rpm -ivh package.rpm | No | Manual installs; offline environments |
Download a local .rpm file | dnf download httpd | N/A | Preparing for a manual rpm installation |
7. Creating a Local YUM Repository
Objective: To demonstrate the process of creating a local YUM repository by mounting an ISO image and configuring the system to use it as a software source. This is a critical skill for managing systems in isolated environments without internet access.
Key Skills Demonstrated:
- Mounting an ISO file as a loop device.
- Creating a custom YUM repository configuration file.
- Verifying the repository is correctly recognized.
- Understanding repository configuration parameters.
Demo Walkthrough & Expanded Explanation
Step 1: Preparation – The ISO File
The foundation of a local repository is the package source. For RHEL, this is typically the installation ISO.
- The Source:
rhel7.iso(or the equivalent for your RHEL version). This file contains all the packages in thePackages/directory and the necessary metadata (repodata/). - Verification: ls pwd Confirms the ISO is present and notes its full path (
/root/rhel7.isoin this case).
Step 2: Creating the Mount Point
A mount point is simply an empty directory that will act as an access point for the contents of the ISO.
sudo mkdir -p /mnt/rhel- Breakdown:
mkdir: Creates a directory.-p: Creates parent directories if they don’t exist. This ensures/mntis created if needed./mnt/rhel: A standard, descriptive location for a temporary filesystem mount.
Step 3: Mounting the ISO File
This step makes the contents of the ISO file accessible to the system as if it were a physical DVD-ROM.
sudo mount -o loop /root/rhel7.iso /mnt/rhel- Breakdown:
mount: The command to attach a filesystem.-o loop: Treats the regular file (rhel7.iso) as a block device (like a CD-ROM)./root/rhel7.iso: The source file./mnt/rhel: The target mount point.
- Expected Warning:
WARNING: ... read-only. This is normal. ISO filesystems are inherently read-only.
Step 4: Creating the Repository Configuration File
This is the core of the setup. It tells yum where to find the local repository.
/etc/yum.repos.d/local.repo- File Location:
/etc/yum.repos.d/local.repoyumreads all files with the.repoextension in this directory.
- Command to Create/Edit:
sudo nano /etc/yum.repos.d/local.repo- Configuration Content:ini[LocalRepo] name=RHEL7 Local Repo baseurl=file:///mnt/rhel enabled=1 gpgcheck=0
- Parameter Breakdown:
[LocalRepo]: A unique ID for the repository. This is whatyumcommands will reference.name: A human-readable description.baseurl=file:///mnt/rhel: Crucial. This specifies the location using thefile://protocol, pointing to our mount point. Note the three slashes (file:///).enabled=1: Tellsyumthis repository is active.gpgcheck=0: Disables GPG signature checking. In a production environment, this is a security risk. It’s used here for simplicity. The best practice is to setgpgcheck=1and import the Red Hat GPG key withrpm --import /mnt/rhel/RPM-GPG-KEY-redhat-release.
[LocalRepo]:
name: CentOS RHEL 9.6 - BASEOS
baseurl=file:///mnt/rhel:
enabled=1
gpgcheck=0CentOS-Stream-BaseOS.repo
[baseos]
name=CentOS Stream 10 - BaseOS
baseurl=https://mirror.stream.centos.org/10-stream/BaseOS/x86_64/os/
gpgcheck=0
enabled=1
gpgkey=https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official
sslverify=0
Step 5: Verification
Always verify your setup to ensure yum can see and use the new repository.
- Verify the Mount:
- lsblk
- Look for a
loopdevice with its mount point listed as/mnt/rhel.
- Look for a
- lsblk
- Verify the Repository:
- yum repolist
- This is the definitive check. Look for
LocalRepoin the output. If it appears, the configuration is successful.
- This is the definitive check. Look for
- yum repolist
- Test Functionality:
- yum –disablerepo=”*” –enablerepo=”LocalRepo”
- list availableThis command disables all other repositories and lists packages available only from your new local repo, confirming it’s working.
- yum –disablerepo=”*” –enablerepo=”LocalRepo”
Key Takeaways for the RHCSA Exam
- Purpose: Local repositories are essential for air-gapped systems or for conserving bandwidth. The exam may present a scenario without internet access.
- The Four-Step Process:
- Create Mount Point:
mkdir -p /mnt/rhel - Mount the ISO:
mount -o loop /path/to/iso /mnt/rhel - Create Repo File: Create a
.repofile in/etc/yum.repos.d/with the correctbaseurl. - Verify: Use
yum repolistto confirm.
- Create Mount Point:
- Understand
baseurl: Thefile:///protocol and the absolute path to the mount point are critical. A single typo here will cause the repository to fail. - Security vs. Practicality: Know what
gpgcheck=0does. While used here for simplicity, be prepared to import a GPG key if required by an exam question. - Persistence: This mount is temporary (non-persistent). To make it survive a reboot, you would need to add an entry to
/etc/fstab. For a one-time exam task, this is likely not required, but understanding the concept is valuable.