I am working on a CentOS box and trying to install a newer version of python. CentOS requires python 2.6.6 in order to run properly. To solve this I installed a second python (v 2.7.6) in /usr/local/bin. I then created a symbolic link to it named python. Unfortunately, because my environment path variable is this:


And /usr/local/bin comes before /usr/bin it uses my new install of python as the default system install, which breaks the CentOS requirement of having python 2.6.6 as the default.

Deleting the symbolic link would fix this problem. However, if I ever install a newer version of python, I'd like to be able to just switch the symbolic link rather than change all of my scripts to point to the newer version.

Is there a way to change the order in which these variables are added to the path? For example, could I make the path look like this:


It's easy to find posts detailing how to add to the path, or overwrite it entirely, but no one seems to do this. Is there a reason why you wouldn't want to change this order?

1 Answer 1


The reason you can't find a guide for changing the order of the path variables is that that's far harder to do than adding to it or replacing it completely.

$PATH is just a variable in your shell. This means that it's easy to replace it (by running PATH=<new path>, or putting that in your .bashrc), and easy to add on to it (with PATH=<new entry>$PATH, because $PATH turns into the current path). But if you want to change the order, you first have to parse it - you need to write a script that understands how the variable works.

For your purposes, it might be best to put the symbolic link in a directory that's not in the default environment path. You could put it in ~/bin/, for example, or you could put it in /usr/local/bin/nopath/.

  • 1
    Yeah that'd work too. After having poked around more I decided that you're right and this probably isn't worth doing. I just stopped being an idiot and changed my symlink to python2, which makes more sense anyway since I'll be doing the same thing with python3. Thanks for the reality check.
    – sage88
    Mar 20, 2015 at 18:06

You must log in to answer this question.

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