How to change default version of python as python3?

By default most of the IDE where we write code for python uses the Python3 interpreter. This is because the support for Python version 2.* has already ended. Although many code base of our operating system and different software application still has code from version 2.

Python 2.7 support ended on January 1, 2020. Now a days every code in python is written in python3. With that in mind, we are writing this quick and easy tweak which helps to make python3 as your default version of python.

This can be done from your linux terminal with the following steps:Check python version on terminal – python --version

Get root user privileges. On terminal type – sudo su

Write down the root user password

Execute this command to switch to python 3.6 –
update-alternatives --install /usr/bin/python python /usr/bin/python3 1

Check python version – python --version

  1. First, make sure that your python version is not python3:
    python --version
  2. Now with your root privileges open superuser prompt:
    sudo su
  3. Now update the alternative to version 3 of python
    update-alternatives --install /usr/bin/python python /usr/bin/python3 1
  4. Exit the root prompt
  5. Finally, check your python version

With this one-liner Linux terminal command, you will now be running your python code and application in Python3 from the terminal.