Two executables with same name in $PATH: How do I force the right one to be used?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Two executables with same name in $PATH: How do I force the right one to be used?
Hello everyone,
I just installed Python 2.6 on a system where I don't have root access. The system previously had Python 2.2 installed on it. While compiling from source, I used the
Code:
--prefix=$HOME/usr
option. So now I have a 'python' executable in $HOME/usr/bin, which runs Python 2.6. I added an
Code:
export PATH=$PATH:$HOME/usr/bin
line to my $HOME/.bashrc file and did 'source .bashrc'. Now 'echo $PATH' shows '$HOME/usr/bin' at the end. Still, the 'python' command brings up the old Python 2.6:
Code:
$which python
/usr/bin/python
How do I force the 'python' command to point to the Python 2.6 executable in '$HOME/usr/bin'?
Thanks, everyone, for the prompt replies!
pixellany, using the full path is what I've been doing so far... I was worried that some script or program that I might use would call 'python' and it would use the wrong one... for the same reason, did not use the alias (in fact, there is also a 'python2.6' executable in $HOME/usr/bin, which works fine).
I did not know about the path order rule. I inverted the assignment as suggested, and 'which python' now reveals the right one.
Thanks once again, everyone!
Cheers,
Guru
P.S. It's nice to have people racing to solve your problems - this is truly a wonderful forum!
Last edited by prasadbrg; 01-14-2009 at 07:38 AM.
Reason: grammar
This is a one-time declaration of the symbol "PATH," known only to this instance of (say...) Python and any of its descendents. It supersedes any exported version of that same symbol, and only in this very-specific context.
You'll probably find that python is a symbolic link to python2.6. At least that's how it's installed on my slackware box.
Gazl, that's what I thought too, at first. I was surprised to see this:
Code:
$ls-l $HOME/usr/bin/
total 7184
-rwxr-xr-x 1 user 125 2009-01-12 19:27 2to3
-rwxr-xr-x 1 user 672 2009-01-13 23:19 f2py
-rwxr-xr-x 1 user 675 2009-01-12 22:14 f2py2.6
-rwxr-xr-x 1 user 113 2009-01-12 19:27 idle
-rwxr-xr-x 1 user 69 2009-01-13 23:27 nosetests
-rwxr-xr-x 1 user 98 2009-01-12 19:27 pydoc
-rwxr-xr-x 2 user 3651483 2009-01-12 19:41 python
-rwxr-xr-x 2 user 3651483 2009-01-12 19:41 python2.6
-rwxr-xr-x 1 user 1438 2009-01-12 19:42 python2.6-config
lrwxrwxrwx 1 user 16 2009-01-12 19:42 python-config -> python2.6-config
-rwxr-xr-x 1 user 18068 2009-01-12 19:27 smtpd.py
sundialsvcs, my apprehension was more about calls to python from scripts, or other programs that I intend to use, which I haven't written. To be honest, I don't have any solid grounds for this apprehension - while I intend to use code that makes calls to python, I'm not sure whether such calls would go through the executable itself (I'm a newbie to these things!). On the other hand, executable python scripts do have this line at the beginning: '#!/usr/bin/env python'. I just wanted to be doubly sure, that all subsequent programs that I run as user, as a rule use the new Python 2.6 executable.
Cheers,
Guru
-rwxr-xr-x 2 user 3651483 2009-01-12 19:41 python
-rwxr-xr-x 2 user 3651483 2009-01-12 19:41 python2.6
Ahhhh, what you seem to have there is a hardlink. Note the '2'.
(I guess whoever packaged it or did the make file forgot the '-s' on the ln command). I don't know if this is the norm with python installs or not.
To confirm that is what has happened you can do a ls -i on both and see if it returns the same inode value, but I'm fairly sure that's it.
Interestingly, the python-config command uses symbolics as expected.
$ ls -il /usr/bin/python*
487364 -rwxr-xr-x 2 root root 5632 May 24 2008 /usr/bin/python
487220 lrwxrwxrwx 1 root root 6 Oct 7 17:40 /usr/bin/python2 -> python
487364 -rwxr-xr-x 2 root root 5632 May 24 2008 /usr/bin/python2.4
this confirms the hard link issue. All the three items were installed by the python RPM. Idem in Fedora. On the contrary, on a OpenSuse system the situation is similar to that reported by GazL for Slackware.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.