Unable to set default python version to python3 in ubuntu Unable to set default python version to python3 in ubuntu python python

Unable to set default python version to python3 in ubuntu


The second line mentioned can be changed to

[sudo] 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 alternatively editing .bashrc is that using the commands with sudo will not work.


EDIT:

I wrote this when I was young and naive, update-alternatives is the better way to do this. See @Pardhu's answer.


Outdated answer:

Open your .bashrc file nano ~/.bashrc. Type alias python=python3on to a new line at the top of the file then save the file with ctrl+oand close the file with ctrl+x. Then, back at your command line typesource ~/.bashrc. Now your alias should be permanent.


To change Python 3.6.8 as the default in Ubuntu 18.04 to Python 3.7.

Install Python 3.7

Steps to install Python3.7 and configure it as the default interpreter.

  1. Install the python3.7 package using apt-get

    sudo apt-get install python3.7

  2. Add Python3.6 & Python 3.7 to update-alternatives

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
  1. Update Python 3 to point to Python 3.7

    sudo update-alternatives --config python3Enter 2 for Python 3.7

  2. Test the version of python

python3 --versionPython 3.7.1