Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-06-2011, 10:39 AM   #1
Registered: Oct 2003
Location: MN
Distribution: CentOS, Fedora
Posts: 182

Rep: Reputation: 30
Question 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!
Old 09-06-2011, 11:13 AM   #2
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,834

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting PATH in kshell in OpenBSD and changing the defult shell to bash AJones *BSD 6 08-15-2011 11:05 PM
Changing the location a module is loaded from without changing the default path zOSGuy Linux - Newbie 2 09-28-2010 03:43 PM
[SOLVED] How can I run a command on another shell without changing the current shell? quanba Other *NIX 3 04-05-2010 01:19 PM
vgcreate command is changing /dev/mapper as PV Name in pvdisplay to /dev/dm-xx path neeravsingh Linux - Enterprise 6 03-23-2010 04:05 AM
Changing my keyboard layout (language) globally by command (shell) Santorres Linux - Newbie 1 05-17-2004 03:04 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:29 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration