When I do

which pip3

I get


but when I try to execute pip3 I get an error as follows:

bash: /usr/bin/pip3: No such file or directory

This is because I recently deleted that file. Now which command points to another version of pip3 that is located in /usr/local/bin but the shell still remembers the wrong path. How do I make it forget about that path?

The which manual says

which returns the pathnames of the files (or links) which would be executed in the current environment, had its arguments been given as commands in
       a strictly POSIX-conformant shell.  It does this by searching the PATH for executable files matching the names of the arguments. It does not follow
       symbolic links.

Both /usr/local/bin and /usr/bin are in my PATH variable, and /usr/local/bin/pip3 is not a symbolic link, it's an executable. So why doesn't it execute?

  • What is the content of /usr/local/bin/pip3?
    – Thomas
    Commented Jan 8, 2017 at 16:13
  • Had you previously run pip3 in that shell while it was in /usr/bin and then moved it? Commented Jan 8, 2017 at 16:14
  • 2
    What do you see if you run hash -t pip3? Commented Jan 8, 2017 at 16:16
  • 1
    @Eric Renouf hash -t pip3 prints /usr/bin/pip3
    – spiderface
    Commented Jan 8, 2017 at 16:24
  • 4
    Unless you have a very good reason, you should always use type eather than which. type is built into a posix shell and tells you what a shell will do, rather than which which tries to guess what the shell will do.
    – icarus
    Commented Jan 8, 2017 at 21:23

2 Answers 2


When you run a command in bash it will remember the location of that executable so it doesn't have to search the PATH again each time. So if you run the executable, then change the location, bash will still try to use the old location. You should be able to confirm this with hash -t pip3 which will show the old location.

If you run hash -d pip3 it will tell bash to forget the old location and should find the new one next time you try.

  • 7
    Or hash -r to clear the whole table.
    – mattdm
    Commented Jan 8, 2017 at 16:27
  • 1
    @spiderface for most bash features it's easier to use help instead of man, so here help hash Commented Jan 8, 2017 at 21:58
  • 3
    @spiderface type hash will tell you that it's a shell builtin, so it doesn't have its own man page. Instead, use help hash or look up hash in bash's man page.
    – deltab
    Commented Jan 8, 2017 at 23:14
  • 1
    Or, if you really want to use man...since hash is a bash builtin, you would want man bash to find it. But what the man page says is essentially what help hash to bash says.
    – MAP
    Commented Jan 8, 2017 at 23:32
  • 3
    Since bash is calling hash -t pip3 underneath, why doesn't it call hash -d pip3 automatically once it discovers the file is not there? Or at least issue a warning and suggestion to run "hash -d pip3"? Commented May 19, 2018 at 17:36

When changing the location of an executable (by moving it or making a new version of an executable available in a different location), use hash -d NAME to force bash to look for it again in PATH. However, if NAME is not in the cache, this will error, so as part of your scripts, use something like this:

if hash -t $NAME >& /dev/null; then 
  hash -d $NAME

You must log in to answer this question.

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