So you’re running through some instructions to configure software on your system, or troubleshoot some problem with a service and you see an error at the command line that says “command not foundâ€. Here is how to locate the packages you need to install in order to use commands that are not available on your system.
CentOS/Red Hat – yum provides
Yum is an excellent package manager with lots of great built in functions. Using  yum provides <command>
 will output a list of packages that provide the command you are trying to run. Here is an example of the output.
sudo yum provides vgscan Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: repo1.sea.innoscale.net * epel: mirror.cogentco.com * extras: mirror.cisp.com * nux-dextop: mirror.li.nux.ro * updates: ftp.linux.ncsu.edu 7:lvm2-2.02.166-1.el7.x86_64 : Userland logical volume management tools Repo : base Matched from: Filename : /usr/sbin/vgscan 7:lvm2-2.02.166-1.el7_3.1.x86_64 : Userland logical volume management tools Repo : updates Matched from: Filename : /usr/sbin/vgscan
Another good thing about  yum provides
 is that it will also search for files. For example if you have a file on your system that you would like to match to a specific package or service  yum
 can get that information for you. For example you might not be sure which package installed the file /etc/sysconfig/authconfig  yum provides
 can get that information for you.
sudo yum provides /etc/sysconfig/authconfig Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: repo1.sea.innoscale.net * epel: mirror.cogentco.com * extras: mirror.cisp.com * nux-dextop: mirror.li.nux.ro * updates: ftp.linux.ncsu.edu authconfig-6.2.8-14.el7.x86_64 : Command line tool for setting up authentication from network : services Repo : base Matched from: Filename : /etc/sysconfig/authconfig authconfig-6.2.8-14.el7.x86_64 : Command line tool for setting up authentication from network : services Repo : installed Matched from: Filename : /etc/sysconfig/authconfig authconfig-6.2.8-10.el7.x86_64 : Command line tool for setting up authentication from network : services Repo : @base Matched from: Filename : /etc/sysconfig/authconfig
Ubuntu
With Ubuntu 14.04 and up you don’t need to run a special command to find a program. For instance if you try to run the command  sar
 without having first installed sysstat you will see the following message:
luke@test-srv01:~$ sar The program 'sar' can be found in the following packages: * sysstat * atsar Try: sudo apt-get install <selected package>
It even tells you how to install the packages you need at the end of the message. Assuming you read the error messages you get when something doesn’t work…. Some of us may or may not be guilty of neglecting to pay attention to error messages.
OpenSUSE/Suse Enterprise Linux – cnf
Similar to Ubuntu running a command that doesn’t exist on your system will provide a suggestion to find the command you need.
luke@test-srv02:~> sar If 'sar' is not a typo you can use command-not-found to lookup the package that contains it, like this: cnf sar
OpenSUSE suggests that we run another command (cnf) to find our package.
luke@test-srv02:~> cnf sar The program 'sar' can be found in the following package: * sysstat [ path: /usr/bin/sar, repository: zypp (SMT-http_smt-ec2_susecloud_net:SLES12-SP2-Pool) ] Try installing with: sudo zypper install sysstat
Suse like Ubuntu gives us a suggestion to install sysstat and even provides the full command to get it. A simple copy and paste should be enough to get the package you want and get back to work.
Luke has an RHCSA for Red Hat Enterpirse Linux 7 and currently works as a Linux Systems Adminstrator in Ohio.
This post, re-published here with permission, was originally published on Luke’s site here.
Leave a Reply