How to Install a Package on CentOS Using yum or dnf
To install a package on CentOS, use the
yum install package-name command for CentOS 7 or earlier, and dnf install package-name for CentOS 8 or later. These commands download and install the package along with its dependencies automatically.Syntax
The basic command to install a package on CentOS is:
yum install package-namefor CentOS 7 and earlier.dnf install package-namefor CentOS 8 and later.
Here, package-name is the name of the software you want to install.
yum and dnf are package managers that handle downloading and installing software and its dependencies.
bash
sudo yum install package-name # or for CentOS 8+ sudo dnf install package-name
Example
This example shows how to install the nano text editor on CentOS 7 using yum. It will download and install nano and any needed dependencies.
bash
sudo yum install nano -y
Output
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package nano.x86_64 0:2.3.1-10.el7 will be installed
...
Installed:
nano.x86_64 0:2.3.1-10.el7
Complete!
Common Pitfalls
- Not running the install command with
sudocan cause permission errors. - Using
yumon CentOS 8 or later may work butdnfis preferred and more up to date. - Typos in the package name will cause "No package found" errors.
- Network issues can prevent downloading packages.
bash
sudo yum install nano -y # Correct way # Wrong: missing sudo yum install nano -y # Error: Permission denied # Wrong: typo in package name sudo yum install nanox -y # Error: No package nanox available.
Quick Reference
| Command | Description |
|---|---|
| sudo yum install package-name | Install package on CentOS 7 or earlier |
| sudo dnf install package-name | Install package on CentOS 8 or later |
| sudo yum update | Update all packages on CentOS 7 or earlier |
| sudo dnf update | Update all packages on CentOS 8 or later |
| yum search package-name | Search for a package (CentOS 7) |
| dnf search package-name | Search for a package (CentOS 8+) |
Key Takeaways
Use
yum install package-name on CentOS 7 and earlier to install packages.Use
dnf install package-name on CentOS 8 and later for package installation.Always run install commands with
sudo to avoid permission errors.Check package names carefully to avoid "No package found" errors.
Ensure your system has internet access to download packages.