authors: [“Luke Rawlins”] date: 2016-12-17 draft: false title: Command not found! description: “Here is how to locate the packages you need to install in order to use commands that are not available on your system.” url: /command-not-found/ tags: – apt – cnf – package management – yum – zypper – CentOS – openSUSE – Ubuntu


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 some_command_name will output a list of packages that provide the command you are trying to run.

Here is an example for what you would see if you were searching for the vgscan command.

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


Something else to keep in mind is that yum provides can 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.

{{< highlight “hllines=9 17 25” >}} 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.x8664 : 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

{{< /highlight >}}

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:

{{< highlight “hl_lines=5” >}} luke@test-srv01:~$ sar The program 'sar' can be found in the following packages: * sysstat * atsar Try: sudo apt-get install {{< /highlight >}}

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.

{{< highlight “hl_lines=6 7” >}} luke@test-srv02:~> cnf sar

The program 'sar' can be found in the following package: * sysstat [ path: /usr/bin/sar, repository: zypp (SMT-httpsmt-ec2susecloud_net:SLES12-SP2-Pool) ]

Try installing with: sudo zypper install sysstat {{< /highlight >}}

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.