How to rehash executables in $PATH with bash

68

15

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.

Patrick B.

Posted 2012-10-22T08:57:13.093

Reputation: 2 058

Answers

100

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

Patrick B.

Posted 2012-10-22T08:57:13.093

Reputation: 2 058

rehash is also a cshell command. – macetw – 2019-06-19T18:22:21.190

5rehash is hash -r in zsh. – Ярослав Рахматуллин – 2012-10-22T12:25:52.930

1@Jaroslav didn't know, thanks (sry for writing your name in latin). – Patrick B. – 2012-10-22T15:04:22.943

9

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'

ElderDelp

Posted 2012-10-22T08:57:13.093

Reputation: 195