How to Install Which Command On CentOS

The which command is a helpful utility for finding the location of executable files in the system’s PATH. It is useful for determining the binary file being executed when multiple versions of the same program are installed or for troubleshooting purposes.

[root@geeks ~]# which grep
-bash: which: command not found

In this short tutorial, we’ll explain how to install the which command on CentOS.

Step 1: Update Your System

Before installing any new packages, it’s a good practice to update your system. To update your CentOS system, run the following command:

sudo yum update -y

Step 2: Install Which Command

To install the which command on CentOS, run the following command:

sudo yum install which -y

This command installs the which package from the default CentOS repositories.

[root@CentOS57 ~]# yum install which
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.ipserverone.com
 * extras: centos.ipserverone.com
 * updates: centos.ipserverone.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package which.i386 0:2.16-7 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================
 Package                Arch                  Version                  Repository             Size
===================================================================================================
Installing:
 which                  i386                  2.16-7                   base                   23 k

Transaction Summary
===================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 23 k
Is this ok [y/N]: y
Downloading Packages:
which-2.16-7.i386.rpm                                                       |  23 kB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : which                                                                       1/1

Installed:
  which.i386 0:2.16-7

Complete!

Step 3: Verify Which Command Installation

After the installation is complete, you can verify that the which command is installed and working correctly by running it with a common command, such as ls:

which ls

The output should display the full path to the ls command, which typically looks like this:

/usr/bin/ls

Programs Mentioned:

  • which – A utility for finding the location of executable files in the system’s PATH, used for troubleshooting and managing installed programs on Unix-like operating systems.
See also  How to Print Unique Lines from a File in Linux?

Conclusion

In this guide, you have successfully installed the which command on your CentOS system. You can now use the which command to locate the full path of executable files in your system’s PATH, helping you troubleshoot and manage your installed programs more effectively.

If you have any questions or suggestions for improvements, please feel free to comment and share your thoughts. We appreciate your feedback and strive to provide the most accurate and informative content possible.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *