11

I am thinking of the use case of this output:

The program 'tiger' is currently not installed. You can install it by typing:
sudo apt-get install tiger

How can I get it to prompt me to install that package? For example it would output this:

The program 'tiger' is currently not installed. You can install it by typing:
sudo apt-get install tiger
# Confirmation can go here
[sudo] password for tim:
The following NEW packages will be installed
  tiger tripwire
0 to upgrade, 11 to newly install, 0 to remove and 0 not to upgrade.
Need to get 8,416 kB of archives.
After this operation, 26.5 MB of additional disk space will be used.
Do you want to continue? [Y/n]  # and/or confirmation can go here

I don't want to have to run it myself. How can I get it to do it automatically, and give me the option to not install?

Tim
  • 33,500

1 Answers1

23

If you set the environment variable COMMAND_NOT_FOUND_INSTALL_PROMPT to 1, like

export COMMAND_NOT_FOUND_INSTALL_PROMPT=1

you will be ask if you want to install the package:

me@myhost:~$ tiger
The program 'tiger' is currently not installed. You can install it by typing:
sudo apt-get install tiger
Do you want to install it? (N/y)

If you answer y it will run

sudo apt-get install tiger

See How do I set environment variables? for how to set environment variables.

N0rbert
  • 103,263