How to disable command-not-found in Ubuntu

Fri, Jun 4, 2010

Tweet this!

If you make a typo on the command line in Ubuntu, or if you type the name of a command that doesn’t exist, the system will automatically provide you with a list of commands that are similar to what you entered; or, if the command exists but the package it belongs to is not installed, it will provide you with the name of the package that you need to install to get that command.  However, this feature does slow down the shell, and if you use the command line often, it does get to be annoying.  This article will show you how to disable the command suggestion feature in Ubuntu.


Example Output of the Command Suggestion Feature

Just so we’re all on the same page, this is the feature I am going to disable:

This is what happens if you make a typo typing a command; it will try to give you a “command spell check”:

root@spirit:/usr/share# picco
No command ‘picco’ found, did you mean:
Command ‘pico’ from package ‘nano’ (main)
Command ‘pico’ from package ‘alpine-pico’ (universe)
picco: command not found

Or, if you type a command that does exist, but is not installed:

root@spirit:/usr/share# vim
The program ‘vim’ can be found in the following packages:
* vim
* vim-gnome
* vim-tiny
* vim-gtk
* vim-nox
Try: apt-get install <selected package>
Disabling the Command Suggestion Feature in Ubuntu

There are two things you need to do to disable this feature.  The first is to remove the package that provides the feature, and the second is to do a quick workaround to bypass a bug which makes the package removal only partially complete.

Step one: Remove the command-not-found package.

sudo apt-get remove command-not-found

If you try executing a non-existent command now, you’ll see that you’ll get a Python error, as shown below.  This is because of the bug referenced above.

root@spirit:/usr/share# picco
/usr/bin/python: can’t find ‘__main__.py’ in ‘/usr/share/command-not-found’

Step Two: To work around this bug, we simply need to run the following command:

sudo mv /usr/share/command-not-found /usr/share/command-not-found.bak

You need to restart your shell for the change to take affect, but once you open a new terminal you’ll see the classic “command not found” bash error:

root@spirit:/home/jdeprizi# picco
bash: picco: command not found
Re-Enabling the Command Suggestion Feature

If, in the future, you decide that you want to re-enable the command suggestion, here is how:

sudo apt-get install command-not-found
sudo mv /usr/share/command-not-found.bak /usr/share/command-not-found

That’s all it takes — just close your terminal and open it again, and you will have the command suggestion available again.

8 Responses to “How to disable command-not-found in Ubuntu”

  1. Chris Goldman says:

    You can do the same thing more simply, in one step:

    sudo apt-get remove command-not-found command-not-found-data

    The “/usr/share/command-not-found” directory is in the “command-not-found-data” package, which is a dependency of the “command-not-found” package.

  2. Benoit says:

    Well. Removing a package from a system for a single user’s sake is an obvious sign of dictatorship.

    Just add the following line in your ~/.bashrc:

    unset command_not_found_handle

    • brankovic says:

      Not so well, it doesnt work. At least on my ubuntu 10 command

      env | grep -i ‘command\|found\|handle’

      gives nothing. But i agree, there must be a way to just disable the feature without resorting to uninstall.

      • rcaron says:

        command_not_found_handle is implemented as a Bash shell function, but the function is not exported. To check to see if you have it enabled, run

        set | grep “command_not_found_handle”

    • Neal Clark says:

      not when it’s the dumbest package ever

    • Think for a second what you _just_ said. Seriously, think it through for a moment. Let’s setup some scenarios.

      1) The system is a personal workstation or laptop. It’s a single-user system, which I’m guessing the OP is alluding to. As the sole owner of my personal system, I should have the ability to install and remove the software as I see fit, without being labeled as a “dictator”. I would also be willing to bet this scenario is the primary target audience for the package. IE- home users.

      2) The system is a multi-user system. Then, two sub-scenarios present themselves:

      2a) The multi-user system is accessed only by a team of system administrators. The administrators _should_ have the capability to found out what software needs to be installed without being prompted. While cute, most administrators will probably find that it gets in the way, and slows their work flow down. Regardless, if a system administrator removes a non-critical non-system package from the server, I would hardly call that “dictatorship”, unless the entire rest of the team disagrees with the removal, and it’s done anyway.

      2b) The multi-user system is accessed only by non-root users, such as a shared shell or web hosting server. If this is the case, then they shouldn’t have the ability to install software packages, so telling them what software package to install is just noise, seeing as though they can’t do anything about it. I guess they could pester the server administrator to install the package, through a ticketing system of some sort. However, if the system administrator finds that the package is not useful, and removes it from the system, from users who can’t install packages anyway, how is that dictatorship?

      The world is full of hate, name calling, and stereotypes. No need to add fuel to the fire.

  3. jpd says:

    i did this, but then commands (like mc)
    which is not installed, but exists
    gave no errors

Leave a Reply

Weekly Poll

What's the best Linux distribution for desktops?

View Results

Loading ... Loading ...

Search TechThrob