Reputation: 64054
I am a non-superuser of a linux machine. Currently it has 2 versions of Python.
When I invoke standard python
command it gave version 2.6
$ python
[neversaint@mach71 ~]$ python
Python 2.6.2 (r262:71600, Jan 28 2011, 13:47:39)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ which python
/opt/somedir/bin/python
It's only when I invoke with python2.7
it gives the version 2.7
[neversaint@mach71 ~]$ python2.7
Python 2.7.6 (default, Nov 11 2013, 13:13:15)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ which phython2.7
/usr/bin/python2.7
My question is how can I set it such that whenever I call $ python
it will give me version 2.7.
Upvotes: 6
Views: 10956
Reputation: 2943
in /usr/bin
create symlink to python27 or whatever python version you have
sudo ln -s python2.7 python
Upvotes: 1
Reputation: 3055
You can simlink it into some directory both accessible to your user and in your $PATH
. For example if /home/<your-username>/local/bin
is in your $PATH
then you can do
ln -s /usr/bin/python2.7 /home/<your-username>/local/bin/python
In this example /home/<your-username>/local/bin
should be in your path before /usr/bin
. If there is no such entry in your $PATH
you can add it there:
export PATH=$HOME/local/bin:$PATH
You can also add this line to .bashrc
or similar to activate it on shell start.
Upvotes: 5
Reputation: 34677
Use a shell alias, alias python=/usr/bin/python2.7
and then python will execute the result of that alias.
Upvotes: 2