The subject says it all, how to rehash the available executables available within one of the $PATHs after having changed things: e.g. removed a binary from one $PATH which is available in another $PATH, changed the $PATH-variable.

up vote 76 down vote accepted

hash -r is what needs to be done. In zsh it is rehash and rehash doesn't exist (by default) in bash.

I use both shells and rehash has been reinforced in my hind-brain for decades, it comes out of my fingers without asking. To accommodate those reflexes I have added alias rehash='hash -r' to my .aliases_bash file, which I test for and source from .bashrc.

To summarize, in .bashrc I use the line:

[[ -f ~/.aliases_bash ]] && . ~/.aliases_bash 

and in /.aliases_bash I use the line

alias rehash='hash -r'

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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