Skip to main content
change python2 to python3

Change default python 2.7 to python 3 in Ubuntu

This is a very common issue for Python beginners, This tutorial helps to change the Python version from python 2.7 to python 3.

By default Ubuntu have inbuilt Python 2, We need to upgrade Python 3, there is a difference between python 2 and python 3.

I am not going into that, Just let you know the main and useful difference is pip.

Python 3 has included pip whereas python 2 does not. We need to install pip externally on python 2.

The Debian Linux installation might have included multiple Python versions. You can run the following ls command to find out what python binary executables are available on your system:

$ ls /usr/bin/python*

You can check the Python version from the command line using the below command:

python --version

The above command, Lets you know which is your default Python version to execute.

Update Packages:

Update the package lists for upgrades and new package installations:

sudo apt update

Install Python 3 in Ubuntu

Install Python 3 if it is not already installed:

sudo apt install python3

How To Change the Python Version in Ubuntu

We can change the python version from python 2.7 to python3+ by creating an alias. You can create a python alias user’s home directory.

alias python='/usr/bin/python3.7'

Now change your default python executable. open .bashrc file and make changes for the above alias:
$ . ~/.bashrc

Check Python Version

Let’s check again python version using the below command: python –version Output:
$ python --version

Output:

Python 3.7.2

Note:

Above steps help to change python version user-wise not system wide.

Leave a Reply

Your email address will not be published. Required fields are marked *