Configuring to detect if a command does not exist, suggest installation

This feature is provided by the command-not-found Install command-not-found package. Ubuntu installs it by default, and makes it active by default in bash but not in zsh. Just add this line to your ~/.zshrc:

. /etc/zsh_command_not_found

Note that you might want to add a check if the file exists if you are sharing your .zshrc across distributions that do not have a /etc/zsh_command_not_found file:

[[ -a "/etc/zsh_command_not_found" ]] && . /etc/zsh_command_not_found

Also, in case you're using oh-my-zsh, there already is a plugin, command-not-found, that you can add to your plugins variable that does the same thing.


If you are using oh-my-zsh, you can just instead looks for "plugins" inside your .zshrc.

Add the command-not-found plugin to the list of plugins to autoload (this plugin is already installed by default).

Like this:

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git command-not-found)

Tags:

Zsh