Change default Python version from 2.4 to 2.6
Asked Answered
G

6

54

I'm wanting to use some newer software that requires Python 2.6, and we currently have both 2.4 and 2.6 installed on our dedicated CentOS server, which looks like this:

$ which python
/usr/local/bin/python
$ which python2.6
/usr/bin/python2.6
$ which python2.4
/usr/local/bin/python2.4
$ ls -l /usr/local/bin/py*
-rwxr-xr-x 1 root root      81 Aug  9  2007 /usr/local/bin/pydoc
-rwxr-xr-x 2 root root 3394082 Aug  9  2007 /usr/local/bin/python
-rwxr-xr-x 2 root root 3394082 Aug  9  2007 /usr/local/bin/python2.4

How can I switch it to start using 2.6 as the default python?

Glyndaglynias answered 26/7, 2010 at 22:45 Comment(3)
possible duplicate of Two versions of python on linux. how to make 2.7 the defaultCorneille
That was asked 3 years later and is for 2.7 not 2.6, so it's not a duplicate.Glyndaglynias
But I think it has a better answer, and the version discussed isn't irrelevant - it's the fact you have two, and want to change the default. " You probably don't actually want to change your default Python......On top of that, monkeying with /usr/bin can break your package manager's ability to manage packages. " - That stands apart from any version issues you have, and shows why the highest voted answer doesn't provide enough info. Also, presumably, you want people to be pointed at the latest answer, so the date thing doesn't matter either.Corneille
L
68

As root:

ln -sf /usr/bin/python2.6 /usr/local/bin/python

This will make a symbolic link from /usr/local/bin/python --> /usr/bin/python2.6 (replacing the old hardlink).

Lafleur answered 26/7, 2010 at 22:52 Comment(5)
according to the question 2.6 is in /usr/binBobodioulasso
and if it seems not to work (i noticed on SLC5), try logging out/inCate
but you still have problems with sudo, i think this answer is not complete. use: update-alternatives --config python see this post: codeghar.wordpress.com/2009/01/27/update-alternatives-in-debianCate
roman, this solution is not meant for any OS in any situation. Changing the default Python in Ubuntu for example, may break your system since package updates are likely to place updates in a place where your alternative python is not going to find them. For this particular question, the OP's default Python is in /usr/local, so it was not an OS default installation. Changing it to point to /usr/bin/python2.6 was therefore safe. Also note that update-alternatives adds symlinks in /usr/bin. If his default is in /usr/local, adding symlinks to /usr/bin won't make a difference.Lafleur
I would make it a symlink instead of a hard link, for clarity.Dante
E
16

As an alternative, you can also just add an alias for the command "python" in the your bash shell's startup file.

so open the startup file: emacs ~/.bashrc

in the editor u append: alias "python" "python2.6"

and restart the shell.

Eightieth answered 2/8, 2011 at 4:3 Comment(0)
R
11

rm /usr/local/bin/python
ln -s /usr/local/bin/python2.6 /usr/local/bin/python

Recapitulation answered 26/7, 2010 at 22:53 Comment(1)
This worked for me, but instead of /usr/local/bin/python2.6 I used /usr/bin/python2.6! :)Catheterize
S
6

Add an alias for the command "python" in the your bash shell's startup file. DON'T change a symbolic link from /usr/bin/python, because changing the default Python (in Ubuntu or Linux Mint for example) may break your system

P.S.: read other answers

Swiger answered 20/3, 2015 at 9:15 Comment(1)
This is correct. For example, trying to change the symbolic links manually in Ubuntu with a command like sudo ln -sf pythonx.y /usr/bin/python, where x.y is the new version you want to make default will probably cause the terminal application to stop launching (and probably other applications as well). See this answer for reference.Thiouracil
A
4

In CentOS

ln -sf /usr/local/bin/python2.6 /usr/local/bin/python
ln -sf /usr/local/bin/python2.6 /usr/bin/python

To check version do:

python -V

Then to fix yum "No module named yum", you should do:

vi `which yum`

and modify #!/usr/bin/python to #!/usr/bin/python2.4

Arria answered 28/7, 2015 at 14:38 Comment(0)
O
1

I had similar problem when using meld, I simply renamed the one under local and it worked. Not a good solution I know, but I can always take it back.

sudo mv /usr/local/bin/python /usr/local/bin/re_python
Offstage answered 6/2, 2014 at 10:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.