When I do
which pip3
I get
/usr/local/bin/pip3
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?
Best Answer
When you run a command in
bash
it will remember the location of that executable so it doesn't have to search thePATH
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 withhash -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.