Tuesday, March 20, 2007

Command Not Found

My machine's BASH has just received a brand new upgrade! From now on, whenever I type a command to open some application which is not installed in my Ubuntu system, the repositories are automatically scanned and, if there is an application with the given name, it will be suggested for installation.

Confused? Here's an example, I'll try to open gedit, which is not installed:

tiagoboldt@Niath:~$ gedit
The program 'gedit' is currently not installed. You can install it by typing:
sudo apt-get install gedit
bash: gedit: command not found
tiagoboldt@Niath:~$

This feature should be installed by default, but you can also install it through the command-not-found package, available in the repositories.

Edit:
There has been some discussion about how fast the output comes out, if it slow or not, so, see it for yourself:
tiagoboldt@Niath:~$ time kedit
The program 'kedit' is currently not installed. You can install it by typing:
sudo apt-get install kedit
Make sure you have the 'universe' component enabled
bash: kedit: command not found

real 0m0.154s
user 0m0.108s
sys 0m0.028s
Less than 0.2 seconds, yes, it is fast!

Digg!

27 comments:

Anonymous said...

command-not-found is part of the default install in the upcoming ubuntu feisty release. smart move on their part to include such a handy tool.

Judith said...

Good greif - there you go being psychic. I have to admit, it is handy to have that available (not that you'd know I was geeky from my URL *rolls eyes*)
and I'm a girl - we're a rare breed *winks*
--
http://www.madspace.co.uk

Anonymous said...

wow, I can see why people love ubuntu so much, they put alot of thought into making it easier to use.

Peter said...

doesn't work with 6.06, package command-not-found not found :-)

J. Morris said...

i've installed this but it doesn't seem to work unless i run

$ command-not-found gedit

shouldn't this execute automagically upon failure to locate a command?

Anonymous said...

J. Morris:
Ensure you've re-logged before expecting command-not-found to work.

IronmanBrian said...

you install all, or almost every, programs with apt-get, this really only helps you the first time (if you didn't know about apt-get). Seems like a waste to me to be reminded about apt-get every time.

Sidney said...

@IronmanBrian: It's not always as easy as you put it. For example, if a app is part of a larger bundle (gnome-games comes to mind, or gnome-system-tools) command-not-found gives you the bundle package, and it also mentions if you need Universe/Multiverse repos.

James Muscat said...

And how long before people start posting on the Ubuntu forums 'When I try to run $appname I get the error "$appname is not installed, you can install it by typing...' What do I do?"

Tiago Sousa said...

Let's leave the apocalyptic comments and stick to reality. When a problem appears, a solution must come out. this package does that. So, let's stick to this solution and try to solve each problem by itself.

WadeMealing said...

Why dont they just pop up a browser window with the package manager ready to go "OMG, click here to install !"

Anonymous said...

Too bad it doesn't use aptitude.
People new to the system, who sees this message, might just think that apt-get is an application. IT IS NOT. It is a showcase of libapt.
Aptitude has one BIG advantage. When you 'aptitude remove' the program it knows what dependencies was installed with the program - and also remove those. Apt-get just removes the 'top' package, and thus leaves a lot of other stuff in the system.

Maybe I should file a bugreport...

Kenneth said...

Let's hope there's an /etc/command-not-found.conf that lets you pick aptitude over apt-get. Perhaps I should check out Ubuntu's launchpad.

HaaTa said...

Well, in Fedora, don't know about Ubuntu. I often have to go /sbin/"command" for a lot of those command-not-found ie. /sbin/modprobe and /sbin/iwconfig

though wlanconfig doesn't need it.

Hope that enlightens someone.

Vincent said...

Wow, that is amazing. And default in Feisty!

Love Calculator said...

Doesn't it slow down anything?

brainwashed said...

@Love Calculator: It does! At least my (feisty powered) laptop needs a second or so to print out this stuff. Truly nothing I would activate on a slow machine, but it's nice anyway.

Brent said...

Well... why doesn't it just say:

"Command not found. Would you like to install it? Yes No"

Anonymous said...

@brent -
I think it probably would be easier by default if it WOULD do that. I don't usually try to type in the commands of programs I don't want to install so I agree.

Command not found.
Would you like to install it?(Y)es/No
Password: lawlercake§
Downloading ...

Anonymous said...

You don't have to log out to get this to work. Just close and open a new terminal. Pretty easy. Very nice. Now this is a must have on all my Ubuntu boxes.

Anonymous said...

Great!!
Work very fine!

Nex3 said...

Personally, I find it rather annoying. Not to say that it's not useful, but I rarely, if ever type a program that's not installed. Granted, I'm a reasonably advanced user, but you need to be somewhat advanced to be mucking about in the terminal in the first place. It most often comes up when I make a typo, and since my system isn't the speediest out there, it's a nuisance to always have it saying "The program 'sl' is not currently installed...". This would be compounded if it actually asked me to install it each time.

That said, it was easy enough to remove, and I can see how it could come in handy.

Anonymous said...

Does it really use the static data from command-not-found-data as backend? Nice for a stable, useless for all other distributions.

butlimous said...

Thanks for the nice post!

Free PS3

VISAY said...

Thanks for this post, it made it easier for me to run: apt-get remove command-not-found.

On my machine this takes about 2-3 seconds sometimes. Maybe the first time it's ran since bootup, or the first time in a new terminal window. But I find the delay annoying, so I removed it. Finally bash is fast again! :)

Still it's a great feature for new users on a fast computer.

Goo said...

i can see the usefulness of this command but i find that it delays the not found response just enough to be annoying (on my Quad core with 4gb ram). I tried apt-get remove and now i'm stuck with a python error
/usr/bin/python: can't open file '/usr/lib/command-not-found': [Errno 2] No such file or directory


and so i downloaded the bash source from http://www.gnu.org/software/bash/ and hooray! no more delay

Kensium said...

Really great work. It’s very handy so that i can enable such an option on a remote Linux machine which has no GUI access. Really happy with it. Ubuntu is a great friendly operating system. sudo aptitude purge command-not-found. this is one command. And it won't bother you anymore. thanks for sharing.

Business Process Outsourcing