Command not found!

By: Luke Rawlins Dec 17, 2016 | 3 minutes read
Share this:

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.

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
<ins style="display: block; text-align: center;" data-ad-client="ca-pub-4075007017829842" data-ad-slot="3427128483" data-ad-layout="in-article" data-ad-format="fluid" class="adsbygoogle"></ins>

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:

[email protected]:~$ 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.

Similar to Ubuntu running a command that doesn’t exist on your system will provide a suggestion to find the command you need.

[email protected]:~> 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.

[email protected]:~> 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.

Related Posts


Managing packages with zypper

Suse Enterprise Linux and it’s upstream community distro openSUSE use a package manager called “zypper”. Zypper is a fast easy to use package management tool. In my opinion, zypper is hands down the best package manager out there. It provides meaningful, easy to read output, it resolves package dependencies quickly, and it has a cool name. Zypper has many options that can be abbreviated; install (in), search (se), info (if), update (up) and lots of others. Read more

Find services that require a restart

Ubuntu offers a live patching utility that allows kernel patches to be installed without requiring a system restart to be applied. Read more about online patching in this post about patching. That said, in many cases other services or processes on your system may need to be restarted after an upgrade. Finding services that need to be restarted in Ubuntu Install debian-goodies sudo apt update sudo apt install debian-goodies Now just run Read more

Uncomplicated Firewall… be careful

If like me, you enjoy the simplicity of UFW (Uncomplicated Firewall) on your Ubuntu servers be careful when you turn it on. UFW doesn’t have any default rules to allow ssh inbound by default, if you aren’t careful when turning it on you could find yourself locked out, and if you don’t have direct console access to the server that could mean being locked out forever! Not a conversation you want to have with a client, or your boss,… or tech support at your friendly cloud provider. Read more


Contact

If you’d like to get in touch, contact with me via email - or follow on Twitter.

[email protected]