How to Install Python 2 on Ubuntu 21.04

Ubuntu has had Python installed by default since at least version 8.04 and since 18.04 LTS the python included in the base system is Python 3. Python 2.7 is not included by default in any new installs. Ubuntu release notes.

We will see how to install Python 2 now

Login to your Ubuntu 21.04 server.

Run the following command to install Python 2 version. During the time of installation it'll ask you permission to install Python 2 press y to continue.

apt install python2

Output:

root@vps:~# apt install python2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib python2-minimal python2.7
  python2.7-minimal
Suggested packages:
  python2-doc python-tk python2.7-doc binutils binfmt-support
The following NEW packages will be installed:
  libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib python2 python2-minimal
  python2.7 python2.7-minimal
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,741 kB of archives.
After this operation, 16.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Next, Check the python version.

python2 -V

Output:

root@vps:~# python2 -V
Python 2.7.18

Done!