Switching between Python versions in Linux

  1. Check what Python version are already installed - ls -ls /usr/bin/python*
  2. If the desired Python version is not installed, install it - sudo apt install python3.X
  3. In case of Couldn't find any package by glob 'Python-X.X.X' :

sudo add-apt-repository ppa:deadsnakes/ppa

  1. Create the alternatives where X is the desired and Y is the main one:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.X 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.Y 2
sudo update-alternatives --config python3
## Here you'll get this print to the screen - 
## Press <enter> to keep the current choice[*], or type selection number:
## Type the number represeting the desired version (in out case X is 1) and press ENTER. 
Example:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
sudo update-alternatives --config python3
Press <enter> to keep the current choice[*], or type selection number: 1
And we'll get this print:
pdate-alternatives: using /usr/bin/python3.8 to provide /usr/bin/python3 (python3) in manual mode
  1. Install the relevant virtualenv - sudo apt install python3.X-venv
  2. Create the virtualenv - python3.X -m venv ENV_NAME
  3. Enter the virtualenv - . /path_to_venv_folder/bin/activate