With modern shells they remember the path to a command you previously ran. So, for example:
bash-4.2$ hash
hash: hash table empty
bash-4.2$ whoami
sweh
bash-4.2$ hash
hits command
1 /usr/bin/whoami
Now if you remove a program (in your case /bin/protoc
) and install it in a new location (/usr/local/bin/protoc
) the current shell will try the old location. And it fails, because the old file isn't there.
You can tell the shell to forget all remembered paths with hash -r
.
That will force it to search the path again.
The which
command doesn't understand the current shell's hash. The type
command is a shell builtin that's more accurate.
type protoc
say? – Stephen Harris Feb 11 '20 at 00:00protoc is hashed (/bin/protoc)
– Chen Xie Feb 11 '20 at 00:08/bin/protoc
but removed it. So tryhash -r
. That will causebash
to forget the old name and look on the path again. – Stephen Harris Feb 11 '20 at 00:09protoc is hashed (/usr/local/bin/protoc)
andprotoc
is working fine, thank you! @StephenHarris – Chen Xie Feb 11 '20 at 00:12