3

If I have two executable files with the same name on $PATH, how does Ubuntu decide which one to use when it is run in the terminal?

For example, my Ubuntu originally had python installed at /usr/bin/python. Recently, I installed Anaconda's distribution of python, which has its own binary installed at /home/karnivaurus/anaconda/bin/python. Then, in my .bashrc file, I entered:

export PATH="/home/karnivaurus/anaconda/bin:$PATH"

So both binaries are now on PATH. But if I run python in the terminal, it always uses the original installation, rather than Anaconda's version. Why is this?

  • Edit your question and add the output of command -v python and the output of ls -lab /home/karnivaurus/anaconda/bin – A.B. Oct 12 '15 at 11:28
1

In order to optimise command lookup, bash keeps a cache, per bash process, of where it found files. So if you typed python and it found it in /usr/bin/, then changing the PATH to provide another python earlier in the PATH will have no effect. You need to also give the bash command:

hash -r

to forget the optimised cached. See help hash. (Of course, I assume you reread the .bashrc or set the PATH explicitly in your shell as well).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.