set default python version ubuntu code example

Example 1: how to change python version on linux

#Check available versions
ls /usr/bin/python*
#Change the used version 3.5 or 3.7 etc
alias python='/usr/bin/python3.x'
#do this other thing
. ~/.bashrc
#Check version 
python --version

Example 2: set python 3 as default ubuntu

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2

Example 3: set python 3 as default ubuntu

sudo update-alternatives --config python

Example 4: set python 3 as default ubuntu

update-alternatives: error: no alternatives for python3