How to Install Python 2 on Ubuntu 20.04

Updated on 10 April, 2025
How to Install Python 2 on Ubuntu 20.04 header image

Introduction

Python 2 was once the backbone of many software projects, but it reached end-of-life in January 2020 and is no longer maintained. However, some legacy applications and scripts still rely on Python 2 to function properly. By default, Ubuntu 20.04 does not come with Python 2 pre-installed, as it focuses on Python 3 for modern development. Installing Python 2 on Ubuntu 20.04 allows you to maintain compatibility with older projects while using a stable and secure operating system.

In this article, you’ll learn how to install Python 2 on Ubuntu 20.04, set it up properly, and ensure it runs alongside Python 3 without conflicts. If you're using FreeBSD instead, check out how to install Python 2 on FreeBSD 14.

1. Install Python 2 on Ubuntu 20.04

SSH to your Ubuntu 20.04 server and install Python 2 with apt.

$ sudo apt install python2

Check the Python version.

$ python2 -V
Python 2.7.17

2. Check Available Python Versions

Check what Python versions are available on system.

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

See if there are Python alternatives configured.

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

3. Set Alternate Versions

For this example, we will set two Python alternatives: Python2 and Python3.

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2

Confirm that both alternatives are ready to be used:

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

Select the alternative Python version.

$ 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. In this example, choose 1 to select Python 2.

Check your python version:

$ python -V
Python 2.7.18rc1

Conclusion

Even though Python 2 is deprecated, it's still possible to install and use with your Vultr VPS running Ubuntu 20.04.

Comments

No comments yet.