Is there a command similar to Linux's command-not-found?

I created Homebrew-command-not-found just for that. It works exactly as you would expect, and supports 5000+ Homebrew formulae. it works with Bash, Zsh, and Fish.

It’s currently limited to correct spellings, e.g.:

$ ghc
The program 'ghc' is currently not installed. You can install it by typing:
  brew install ghc
$ ghv
ghv: command not found

Install it with brew tap homebrew/command-not-found, then add the following line to your ~/.bashrc/~/.zshrc:

HB_CNF_HANDLER="$(brew --repository)/Library/Taps/homebrew/homebrew-command-not-found/handler.sh"
if [ -f "$HB_CNF_HANDLER" ]; then
  source "$HB_CNF_HANDLER";
fi

We’d welcome a PR for misspelling support, though.


Searching Google for "homebrew command-not-found" (without the quotes) one of the results was: Ubuntu’s command-not-found equivalent for Homebrew on OSX

I have not personally tried using it, so I cannot comment on how well it may work.


One option is to use zsh, which has a CORRECT option that will suggest commands with a "nearby" spelling. Personally, I use zsh and prezto, which results in this:

zsh and prezto auto correct

It's nice because the command is red while typing if it's not a valid program name, which means I usually catch the typo before I even press enter. Valid command names are green, though, so I know when I've typed it right.

zsh can be installed via homebrew, and then adding something like prezto on top of that is easy (it's just a git clone ..., ln -s ..., and chsh -s /usr/local/bin/zsh).