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


Results from type command:

$ type node
node is hashed (/usr/local/bin/node)
$ type foo
-bash: type: foo: not found
  • Can you update your question with the output of both type node and type foo (though probably only the first really is helpful). Jun 13, 2016 at 17:15
  • @EricRenouf, okay, I did.
    – jds
    Jun 13, 2016 at 17:17
  • 2
    It's probably that 'node' is a symbolic link from /usr/bin/node -> /usr/local/bin/node and the latter is not available hence the error, which would suggest /usr/local/bin/node was deleted after the symbolic link was created.
    – likewhoa
    Jun 13, 2016 at 17:17

2 Answers 2


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 thinks node is at /usr/local/bin/node, skipping the PATH lookup, and calling /usr/local/bin/node directly, using execve(). Since when node isn't there anymore, execve() returns ENOENT error, means no such file or directory, bash reported that error to you.

In bash, you can remove an entry from hash table:

hash -d node

or remove the entire hash table (works in all POSIX shell):

hash -r
  • 2
    Note that it doesn't have to be /usr/local/bin/node that's missing; if that file is a dynamically linked executable, and one of the dependencies is missing, you'll get the same "No such file or directory" message. This can drive you crazy until you try ldd on that file. Jun 14, 2016 at 15:49
  • @GuntramBlohm but on some Linux distros bash is patched to print more understandable error messages, like progname: error while loading shared libraries: badLib.so.1: cannot open shared object file: No such file or directory (or it might be not bash in this particular case, but ld-linux.so).
    – Ruslan
    Jun 14, 2016 at 16:45
  • @Ruslan In my experience you get the "error while loading shared libraries" if it's an "ordinary" shared library that's missing, and the inexplicable "No such file or directory" if it's the dynamic linker itself that's missing. This makes sense when you realize that the former case is detected by the dynamic linker, whereas the latter case is detected by the kernel, and it's much easier for the dynamic linker to print a helpful message (execve writing to stderr as a side effect on failure would probably violate POSIX or something)
    – zwol
    Jun 14, 2016 at 17:17
  • @zwol ah, right, that's what some distros (e.g. CentOS) patch bash for. Such patched version then prints errors like /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory.
    – Ruslan
    Jun 14, 2016 at 17:19

I found on Ubuntu Linux 16.04 that "No such file or directory" means you have to switch your current working directory while "command not found" means you have to use apt-get install xxxyyy_zzz to fix the problem.

  • 10
    If your cwd has any influence on what will be found or not (unless you prefix it with ./), your PATH is set up in a rather unsafe manner. And a command not being found is not always a problem you want to fix :) Jun 14, 2016 at 9:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .