Home » Scripting and Automation » Python » How to change python version in Ubuntu ?

How to change python version in Ubuntu ?

If you have more than one python version installed like below,

$ ls -lh /usr/bin/python*
/usr/bin/python -> python2.7
/usr/bin/python2 -> python2.7
/usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
/usr/bin/python2-config -> python2.7-config
/usr/bin/python3 -> python3.6

here, as you can see we have two python versions installed, python 2.7 and python 3.6. Lets check what is our current active python version,

$ python -V
Python 2.7

Now, lets say we want to change the python version from 2.7 to 3.6 , then for your current user you can do the same by only changing environment variable from .bashrc as,

$ vim ~/.bashrc 

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

Now, either reset the current terminal by typing “reset” command or close and start another terminal and if we check the python version now,

$ python -V
Python 3.6.9

Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment