How to Install Python 2 on Ubuntu 20.04

Python 2 has been removed from Ubuntu, but if you use programs that are more obsolete, then you need Python. It must be installed and configured.

Install Python 2

Connect to your server Ubunt 20.04 and install Python 2 with apt.

$ sudo apt install python2

Check out the Python version

$ python2 -V
Python 2.7.17

Check available Python versions

It is necessary to check the available versions in the system

$ ls /usr/bin/python*
/usr/bin/python2  /usr/bin/python2.7  /usr/bin/python3  /usr/bin/python3.8

Next, look for customized Python alternatives

$ sudo update-alternatives --list python
update-alternatives: error: no alternatives for python

Install alternate versions

To do this, install alternatives to Python 2 and Python 3.

$ 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 both of these alternatives work ready to use.

$ sudo update-alternatives --list python
/usr/bin/python2
/usr/bin/python3

Choose an alternate version of Python.

$ 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 <enter> to keep the current choice[*], or type selection number: 1

Enter your selection, on Python 2.

Check out the Python version:

$ python -V
Python 2.7.18rc1

Was this article helpful?

Related Articles

1 Comment