I run xubuntu and am switching from bash to zsh as the default shell. It works great - only thing I miss from the bash days is this: when I execute a command which isn't installed, bash would tell me the apt-get command line for installing it. Is it possible to achieve this with zsh?


This seems to be already answered here.

The response is issued by the command-not-found package, which you obviously already have, since bash is responding as you wish. It is simply a matter of configuring zsh to use it.

After trying the solution in Ubuntu I found that the file mentioned in /etc doesn't exist, but it is simply a matter of adding this line to .zshrc:

command_not_found_handler() {/usr/lib/command-not-found "$1"}

If you want to suppress zsh's own command not found message, you can add return 0 to the handler, BUT this will not show an error in $? afterwards.

There is more information on how bash interfaces to the package here.

Note that the bash handler is called command_not_found_handle(), whereas in zsh it's command_not_found_handler().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.