0
0
Linux-cliHow-ToBeginner ยท 3 min read

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-name for CentOS 7 and earlier.
  • dnf install package-name for 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 sudo can cause permission errors.
  • Using yum on CentOS 8 or later may work but dnf is 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

CommandDescription
sudo yum install package-nameInstall package on CentOS 7 or earlier
sudo dnf install package-nameInstall package on CentOS 8 or later
sudo yum updateUpdate all packages on CentOS 7 or earlier
sudo dnf updateUpdate all packages on CentOS 8 or later
yum search package-nameSearch for a package (CentOS 7)
dnf search package-nameSearch 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.