Monday, February 16, 2015

Howto change default Python version 2.7 to 3.4 in Ubuntu 14.04.1 LTS 64bit

Ubuntu 14.04 LTS comes with both Python version 2.7 and 3.4. The default Python version is 2.7 and update-alternatives is not configured to switch Python versions

$ sudo update-alternatives --config python
update-alternatives: error: no alternatives for python

1. So to configure alternatives for Python 2.7 & 3.4 we need to configure update-alternatives as follows

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode

2. And now you can switch between Python versions

$ sudo update-alternatives --config python
[sudo] password for linuxuser: 
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.4   2         auto mode
* 1            /usr/bin/python2.7   1         manual mode
  2            /usr/bin/python3.4   2         manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in manual mode

No comments:

Post a Comment