Yum command not found on CentOS/RHEL server

This is a new problem I am getting whenever I run yum install htop, I am getting the following error on my screen:

-bash: yum: command not found

How do I fix this error on a CentOS 7 Linux server?

Yum is located at /usr/bin/yum. Make sure yum is in path:

echo "$PATH"

You can always set path as follows:

export PATH=$PATH:/usr/bin

For root user PATH should be as follows:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

Make sure yum can be located:

type -a yum

Once found you can run it as follows:

yum update
yum install htop
/usr/bin/yum update

If yum is missing you can install it from DVD/CD. You need to locate a package called yum*.rpm and install it with:

rpm -ivh /path/to/cdrom/yum*.rpm
[root@samratsukhi Link to Linux Programs]# rpm -ivh /path/to/cdrom/yum*.rpm
error: File not found by glob: /path/to/cdrom/yum*.rpm
[root@samratsukhi Link to Linux Programs]# rpm -ivh yum*.rpm
warning: yum-4.2.19-1.1.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f6ab3975: NOKEY
error: Failed dependencies:
	dnf = 4.2.19-1.1 is needed by yum-4.2.19-1.1.noarch
	dnf >= 4.2.17 is needed by yum-utils-4.0.14-1.1.noarch
	dnf-plugins-core = 4.0.14-1.1 is needed by yum-utils-4.0.14-1.1.noarch
	python3-dnf >= 4.2.17 is needed by yum-utils-4.0.14-1.1.noarch

Are you using CentOS 8? Either way install those packages too using the rpm:

rpm -ivh dnf*.rpm python3-dnf*.rpm yum*.rpm

Hi,
I am using RHEL4,
When I was trying above steps it is not working for me. Please help me.

Thanks,
Raju

Hi @Rajubudde,

Support for RHEL 4 ended in 2017 and no longer recommended. No updates available.

I am using RHEL 8.1

dhcp-10-14-22-97:~ # type -a yum
-bash: type: yum: not found
dhcp-10-14-22-97:~ # /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin
-bash: /sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin: No such file or directory
dhcp-10-14-22-97:~ # rpm -ivh /path/to/cdrom/yum*.rpm
error: File not found by glob: /path/to/cdrom/yum*.rpm
dhcp-10-14-22-97:~

On RHEL 8.x, dnf is real package manage. Do you have dnf?

ls -l /usr/bin/dnf
ls -l /bin/dnf