Most Linux commands come in packages. If a command is missing, install the package that provides it. CentOS gives you several tools for this.
Method 1: yum
yum is the classic package manager of CentOS 7:
sudo yum install <package_name>
Example, to install the which command:
sudo yum install which -y
The -y option answers "yes" to the confirmation question.
Method 2: dnf
dnf replaces yum in CentOS 8 and later (and in AlmaLinux and Rocky Linux). It is faster and handles dependencies better.
sudo dnf install <package_name>
Example:
sudo dnf install which -y
Method 3: rpm
rpm is the low-level tool that installs a single .rpm file. It does not fetch dependencies for you.
sudo rpm -i <package_name.rpm>
Example:
sudo rpm -i which-2.22-1.el7.rpm
yum or dnf when you can, because they also install what the package needs.Method 4: Flatpak
Flatpak packages carry their own dependencies. Install Flatpak:
sudo yum install flatpak -y
Add the Flathub repository:
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
Install an app:
flatpak install flathub <package_name>
Find which package gives a command
If a command is not found, ask the package manager which package provides it:
sudo yum provides */which
On dnf systems use sudo dnf provides */which.
Other ways
- Graphical software center. Search for the package and click Install.
- Third-party repositories. Some commands are not in the default repositories. Add a trusted repository such as EPEL (
sudo yum install epel-release) and install from it.
Important notes
- Back up the system before big changes.
- Use
sudoto install, remove or update packages. - Be careful with third-party repositories and install only from sources you trust.
- Read the documentation of a command before you use it.
Quick recap
yum installon CentOS 7,dnf installon newer versions.- Use
rpm -ifor single files and Flatpak for self-contained apps.