LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Changing the path for a shell command (https://www.linuxquestions.org/questions/linux-newbie-8/changing-the-path-for-a-shell-command-901433/)

Phaethar 09-06-2011 09:39 AM

Changing the path for a shell command
 
Hey all,

This seems like an easy question, but for the life of me I can't find anything about how to do it.

I have a CentOS 5 system that has 2 versions of Python installed: 2.4 and 2.7. CentOS comes with 2.4 installed, and that executes out of /usr/bin. When 2.7 was installed, it placed it's own shell script into /usr/local/bin. Now, the system is favoring the 2.7 version instead of the 2.4. Running which python returns /usr/local/bin/python. I need to change it to it defaults to /usr/bin again, and it needs to be for all users (system wide).

Thanks in advance for any help!

David the H. 09-06-2011 10:13 AM

The directories in PATH are simply checked in the order that they appear. If /usr/local/bin comes before /usr/bin, and a program with that name exists there, then that's the one it will use. However, simply changing the PATH order might affect other programs too, so alter it only if you're absolutely sure you won't break anything. You should consider possible future needs too, of course.

Your best option therefore, if possible, would be to move/rename/recompile the 2.7 version so that it doesn't appear in that directory, or otherwise doesn't conflict in name with the 2.4 executable. Moving it to its own subdirectory inside /usr/local/bin would work, for example.

Another possibility would be to set an alias or shell function to override the path search, but you'd still have to hard-code the location in scripts.


The default path is most likely set in your /etc/bashrc, of course, or one of your other shell startup scripts.


All times are GMT -5. The time now is 08:28 PM.