0
0
Linux CLIscripting~5 mins

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

Choose your learning style9 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.