Unable to set default python version to python3 in ubuntu

RejeeshChandran picture RejeeshChandran · Feb 1, 2017 · Viewed 367k times · Source

I was trying to set default python version to python3 in Ubuntu 16.04. By default it is python2 (2.7). I followed below steps :

update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3

but I'm getting the following error for the second statement,

rejeesh@rejeesh-Vostro-1015:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs <link> <name> <path> <priority>

Use 'update-alternatives --help' for program usage information.   

I'm new to Ubuntu and Idon't know what I'm doing wrong.

Answer

Pardhu picture Pardhu · May 14, 2018

The second line mentioned can be changed to

update-alternatives --install /usr/bin/python python /usr/bin/python3 10

This gives a priority of 10 for the path of python3. The disadvantage of editing .bashrc file is that it will not work while using the commands with sudo.

Update: Please use sudo while running the command like this:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10