Install Python 2 on Linux Ubuntu 20.04
Python 2 version is officially dead so it’s not available as a default installation on Ubuntu 20.04.
Although Python 2 is dead, you may still need to run some legacy apps using this version so even if not installed by default in your system, it can be easily installed with a few commands.
Throughout this article, you will see:
– How to install Python 2 on Ubuntu 20.04
– How to make Python 2 as a default python interpreter in Ubuntu 20.04
How to Install Python 2 on Ubuntu 20.04?
Head back to your terminal and run the following command to install Python 2 on your Ubuntu 20.04 machine:
$ sudo apt install python2
$ python2 -V Python 2.7.17
Next, let’s make Python 2 the default version instead of Python 3.
Start by checking if you have some python alternatives configured using the following command:
$ sudo update-alternatives --list python update-alternatives: error: no alternatives for python
This means our system doesn’t have any python alternatives configured.
Now we need to set two Python alternatives, i.e Python2 and Python3 by running the following commands:
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1 $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
Make sure the two alternatives can be used using the following command:
$ sudo update-alternatives --list python /usr/bin/python2 /usr/bin/python3
Next, set Python 2 as the default by running the following command:
$ sudo update-alternatives --config python There are 2 choices for the alternative python (providing /usr/bin/python). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/python3 2 auto mode 1 /usr/bin/python2 1 manual mode 2 /usr/bin/python3 2 manual mode Press to keep the current choice[*], or type selection number: 1
Simply, type the corresponding number. For example to set Python 2 we need to type
Finally, you ensure you have made Python 2 the default version in your system by running the following command:
$ python -V Python 2.7.17
In this article, we have seen how to install Python 2 in our Ubuntu 20.04 development machine and how to configure it to be the default version instead of Python 3.
Keep in mind that Python 2 is officialy dead so it’s not recommended to use it for new projects,