Python 2 reached its official end of life on January 1, 2020, and is no longer actively maintained. Although deprecated, certain older applications and scripts still rely on it. While it is not advised for new projects, Python 2 can still be installed on Ubuntu 22.04 using packages from the official universe repository.
This guide explains how to install Python 2 on Ubuntu 22.04, configure pip for Python 2, and confirm the installation. If you are using another operating system, you may want to review our guides for installing Python and Pip on Ubuntu 24.04 or setting up Python 2 on FreeBSD 14.0.
Prerequisites
- Access to an Ubuntu 22.04 system with a non-root user who has sudo privileges.
Matching infrastructure at centron
Scripts and services eventually need an environment that keeps running: ccloud³ VMs from €3.12 per month, billed by the hour. Rent a cloud server →
Enable the Python Repository
Python 2 is not part of Ubuntu’s default setup, but it can still be obtained from the official universe repository. The following steps prepare your system to locate and install older Python releases.
Update the package index
$ sudo apt updateInstall repository management tools
$ sudo apt install -y software-properties-commonCheck the available Python 2 version
$ apt policy python2Sample output:
python2:
Installed: (none)
Candidate: 2.7.18-3
Version table:
2.7.18-3 500
500 http://archive.ubuntu.com/ubuntu jammy/universe amd64 PackagesFor Ubuntu 22.04, Python 2.7.18 is the most recent version available.
Install Python 2
Install Python 2 from the official Ubuntu repository and verify the installation.
Install Python 2
$ sudo apt install -y python2Check the Python version
$ python2 --versionSample output:
Python 2.7.18Install pip for Python 2
pip is Python’s standard package manager, allowing installation and management of packages from the Python Package Index (PyPI). Since Python 2 does not come with pip by default, it must be installed manually.
Download the get-pip.py script
$ curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.pyInstall pip for Python 2
$ sudo python2.7 get-pip.pyVerify pip installation
$ pip2.7 --versionSample output:
pip 20.3.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)Test and Use Python 2
After installation, test the Python 2 interpreter to ensure it runs properly.
Start the Python 2 shell
$ python2Run a simple print statement
>>> print('Hello, World!')Sample output:
Hello, World!Exit the Python shell
>>> quit()Conclusion
Python 2 is now installed alongside the default Python 3 environment on Ubuntu 22.04. This configuration lets you maintain legacy applications that depend on Python 2 while still using modern Python 3 tools.
For more detailed information on maintaining Python 2 projects, consult the official Python 2.7 documentation.
Testen Sie Ihr Setup auf ccloud³
Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.