Bird
Raised Fist0
Linux CLIscripting~5 mins

yum/dnf (RHEL/CentOS) basics in Linux CLI - Commands & Configuration

Choose your learning style10 modes available
Introduction
Installing and managing software on RHEL or CentOS Linux can be tricky without the right tools. Yum and Dnf are package managers that help you easily install, update, and remove software packages from your system.
When you want to install new software like a web server or text editor on your CentOS or RHEL system.
When you need to update all your installed software to the latest versions for security and features.
When you want to remove software you no longer need to free up space.
When you want to check if a specific software package is available or installed.
When you want to clean up cached files to save disk space.
Commands
This command installs the 'nano' text editor without asking for confirmation because of the '-y' flag. We use 'sudo' to run it with admin rights.
Terminal
sudo dnf install nano -y
Expected OutputExpected
Last metadata expiration check: 0:00:10 ago on Thu 01 Jun 2023 10:00:00 AM UTC. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: nano x86_64 5.9-1.el8 baseos 1.2 M Transaction Summary ================================================================================ Install 1 Package Total download size: 1.2 M Installed size: 3.5 M Downloading Packages: nano-5.9-1.el8.x86_64.rpm 1.2 MB/s | 1.2 MB 00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Preparing : 1/1 Installing : nano-5.9-1.el8.x86_64 1/1 Running scriptlet: nano-5.9-1.el8.x86_64 1/1 Verifying : nano-5.9-1.el8.x86_64 1/1 Installed: nano.x86_64 0:5.9-1.el8 Complete!
→
-y - Automatically answer yes to prompts
This command updates all installed packages to their latest versions without asking for confirmation.
Terminal
sudo dnf update -y
Expected OutputExpected
Last metadata expiration check: 0:00:05 ago on Thu 01 Jun 2023 10:05:00 AM UTC. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Upgrading: bash x86_64 5.0.17-2.el8 baseos 1.1 M Transaction Summary ================================================================================ Upgrade 1 Package Total download size: 1.1 M Downloading Packages: bash-5.0.17-2.el8.x86_64.rpm 1.1 MB/s | 1.1 MB 00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Preparing : 1/1 Upgrading : bash-5.0.17-2.el8.x86_64 1/1 Running scriptlet: bash-5.0.17-2.el8.x86_64 1/1 Verifying : bash-5.0.17-2.el8.x86_64 1/1 Upgraded: bash.x86_64 0:5.0.17-2.el8 Complete!
→
-y - Automatically confirm all prompts
This command removes the 'nano' package from the system without asking for confirmation.
Terminal
sudo dnf remove nano -y
Expected OutputExpected
Last metadata expiration check: 0:00:02 ago on Thu 01 Jun 2023 10:10:00 AM UTC. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: nano x86_64 5.9-1.el8 installed 3.5 M Transaction Summary ================================================================================ Remove 1 Package Running transaction check Running transaction test Transaction test succeeded Running transaction Preparing : 1/1 Removing : nano-5.9-1.el8.x86_64 1/1 Running scriptlet: nano-5.9-1.el8.x86_64 1/1 Verifying : nano-5.9-1.el8.x86_64 1/1 Removed: nano.x86_64 0:5.9-1.el8 Complete!
→
-y - Skip confirmation prompt
This command checks if the 'nano' package is installed on the system.
Terminal
dnf list installed nano
Expected OutputExpected
Installed Packages nano.x86_64 5.9-1.el8 @baseos
This command cleans all cached files from the package manager to free up disk space.
Terminal
sudo dnf clean all
Expected OutputExpected
Cleaning repos: baseos appstream extras Cleaning up everything Cache directory: /var/cache/dnf is cleaned.
Key Concept

If you remember nothing else from yum/dnf basics, remember: use 'install' to add software, 'update' to upgrade all, and 'remove' to delete software, always with sudo and '-y' to automate.

Common Mistakes
Running 'dnf install nano' without sudo
You get a permission denied error because installing software needs admin rights.
Always prefix with 'sudo' to run as administrator: 'sudo dnf install nano'
Forgetting the '-y' flag and expecting no prompts
The command pauses and waits for you to type 'y' or 'n', which can block automation.
Add '-y' to automatically confirm prompts: 'sudo dnf install nano -y'
Trying to remove a package that is not installed
The package manager will show an error saying the package is not found.
Check if the package is installed first with 'dnf list installed nano' before removing.
Summary
Use 'sudo dnf install package -y' to install software without prompts.
Use 'sudo dnf update -y' to upgrade all installed packages automatically.
Use 'sudo dnf remove package -y' to uninstall software without confirmation.
Use 'dnf list installed package' to check if a package is installed.
Use 'sudo dnf clean all' to clear cached files and save disk space.

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