<\/span><\/h2>\r\n\r\n\r\n\r\nIn the first step of this tutorial we are going to install the default Python2 and Python3 versions in Ubuntu 20.04.<\/p>\r\n\r\n\r\n\r\n
To install the default Python2 version execute the following command:<\/p>\r\n\r\n\r\n\r\n
sudo apt install python2 -y<\/pre>\r\n\r\n\r\n\r\nTo check if the Python2 version is installed successfully execute the command below:<\/p>\r\n\r\n\r\n\r\n
python2 -V<\/pre>\r\n\r\n\r\n\r\nYou should get the following output:<\/p>\r\n\r\n\r\n\r\n
root@vps:~# python2 -V\r\nPython 2.7.18<\/pre>\r\n\r\n\r\n\r\nTo install the default Python3 version execute the following command:<\/p>\r\n\r\n\r\n\r\n
sudo apt install python3 -y<\/pre>\r\n\r\n\r\n\r\nTo check if the Python3 version is installed successfully execute the command below:<\/p>\r\n\r\n\r\n\r\n
python3 -V<\/pre>\r\n\r\n\r\n\r\nYou should get the following output:<\/p>\r\n\r\n\r\n\r\n
root@vps:~# python3 -V\r\nPython 3.8.10\r\n<\/pre>\r\n\r\n\r\n\r\n<\/span>Step 2. Install Multiple Python Versions<\/span><\/h2>\r\n\r\n\r\n\r\nIn the previous steps we installed the default Python versions in Ubuntu 20.04, Python3.8, and Python2.7. Now we are going to install lower Python3 versions such as Python3.7<\/b>, Python3.6<\/b> and Python3.5<\/b><\/p>\r\n\r\n\r\n\r\n
To install Python3.7<\/b>, you need to add the repository first:<\/p>\r\n\r\n\r\n\r\nsudo apt install software-properties-common\r\nsudo add-apt-repository ppa:deadsnakes\/ppa\r\nsudo apt update\r\n<\/pre>\r\n\r\n\r\n\r\nOnce, the repo is added and the system is updated, execute the command below:<\/p>\r\n\r\n\r\n\r\n
sudo apt install python3.7 -y<\/pre>\r\n\r\n\r\n\r\nTo check if the Python3.7 is installed successfully, run the following command:<\/p>\r\n\r\n\r\n\r\n
python3.7 -V<\/pre>\r\n\r\n\r\n\r\nYou should receive the following output<\/p>\r\n\r\n\r\n\r\n
root@vps:~# python3.7 -V\r\nPython 3.7.12<\/pre>\r\n\r\n\r\n\r\nNext version for installing is the Python3.6<\/b> version. Since the repo is already added you need to execute the following command to install Python3.6<\/p>\r\n\r\n\r\n\r\nsudo apt install python3.6 -y<\/pre>\r\n\r\n\r\n\r\nTo check if the Python3.6 is installed successfully, run the following command:<\/p>\r\n\r\n\r\n\r\n
python3.6 -V<\/pre>\r\n\r\n\r\n\r\nYou should receive the following output<\/p>\r\n\r\n\r\n\r\n
root@vps:~# python3.6 -V\r\nPython 3.6.15<\/pre>\r\n\r\n\r\n\r\nThe last Python version that we are going to install is the Python3.5 version:<\/p>\r\n\r\n\r\n\r\n
sudo apt install python3.5 -y<\/pre>\r\n\r\n\r\n\r\np>To check if the Python3.5 is installed successfully, run the following command:<\/p>\r\n\r\n\r\n\r\n
python3.5 -V<\/pre>\r\n\r\n\r\n\r\nYou should receive the following output<\/p>\r\n\r\n\r\n\r\n
root@vps:~# python3.5 -V\r\nPython 3.5.10\r\n<\/pre>\r\n\r\n\r\n\r\n<\/span>Step 3. Create Python Symlinks<\/span><\/h2>\r\n\r\n\r\n\r\nOnce, multiple Python versions are installed, we need to add the symbolic links for every Python version separately. We are going to create symlinks for the following Python versions respectively: Python2.7, Python3.5, Python3.6, Python3.7, and Python3.8 Next to the symlink we are going to add the group name python<\/b> and the option number.<\/p>\r\n\r\n\r\n\r\n
Execute the following commands one by one:<\/p>\r\n\r\n\r\n\r\n
sudo update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python2.7 1\r\nsudo update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python3.5 2\r\nsudo update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python3.6 3\r\nsudo update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python3.7 4\r\nsudo update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python3.8 5\r\n<\/pre>\r\n\r\n\r\n\r\nAfter execution, you should receive the following output:<\/p>\r\n\r\n\r\n\r\n
root@vps:~# sudo update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python2.7 1\r\nupdate-alternatives: using \/usr\/bin\/python2.7 to provide \/usr\/bin\/python (python) in auto mode\r\nroot@vps:~# sudo update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python3.5 2\r\nupdate-alternatives: using \/usr\/bin\/python3.5 to provide \/usr\/bin\/python (python) in auto mode\r\nroot@vps:~# sudo update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python3.6 3\r\nupdate-alternatives: using \/usr\/bin\/python3.6 to provide \/usr\/bin\/python (python) in auto mode\r\nroot@vps:~# sudo update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python3.7 4\r\nupdate-alternatives: using \/usr\/bin\/python3.7 to provide \/usr\/bin\/python (python) in auto mode\r\nroot@vps:~# sudo update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python3.8 5\r\nupdate-alternatives: using \/usr\/bin\/python3.8 to provide \/usr\/bin\/python (python) in auto mode\r\n<\/pre>\r\n\r\n\r\n\r\n