For example:
$ node
-bash: /usr/local/bin/node: No such file or directory
$ foo
-bash: foo: command not found
What's the difference? In both cases, node
and foo
are invalid commands, but it seems like Unix just can't find the node
binary? When uninstalling a program, e.g. node
, is there a way to clean this up so that I get
$ node
-bash: node: command not found
EDIT:
Results from type
command:
$ type node
node is hashed (/usr/local/bin/node)
$ type foo
-bash: type: foo: not found
Best Answer
That's because
bash
remembered your command location, store it in a hash table.After you uninstalled
node
, the hash table isn't cleared,bash
still thinksnode
is at/usr/local/bin/node
, skipping thePATH
lookup, and calling/usr/local/bin/node
directly, usingexecve()
. Since whennode
isn't there anymore,execve()
returnsENOENT
error, means no such file or directory,bash
reported that error to you.In
bash
, you can remove an entry from hash table:or remove the entire hash table (works in all POSIX shell):