
Python 2 reached end of life on January 1, 2020, and is no longer officially maintained. Despite its deprecation, some legacy applications and scripts still depend on it. While not recommended for new development, you can install Python 2 on Ubuntu 22.04 using packages available in the official universe repository.
This article shows how to install Python 2 on Ubuntu 22.04, set up pip
for Python 2, and verify the installation. If you're working on a different platform, consider reviewing our articles on installing Python and Pip on Ubuntu 24.04 and installing Python 2 on FreeBSD 14.0.
Prerequisites
Before you begin, you need to:
- Have access to an Ubuntu 22.04 instance as a non-root sudo user.
Add the Python Repository
Python 2 is no longer included in Ubuntu's default installation, but you can still install it from the official universe
repository. The following steps ensure your system is properly configured to locate and install older Python versions.
Update the package index.
console$ sudo apt update
Install the required tools for managing repositories.
console$ sudo apt install -y software-properties-common
Check the available version of Python 2 in the
APT
sources.console$ apt policy python2
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 Packages
Python 2.7.18 is the latest version available for Ubuntu 22.04.
Install Python 2
Install Python 2 from the official Ubuntu repository and confirm the installation.
Install Python 2.
console$ sudo apt install -y python2
Verify the Python version.
console$ python2 --version
Output:
Python 2.7.18
Install pip
for Python 2
pip
is the standard package manager for Python. It allows you to install and manage packages from the Python Package Index (PyPI). Python 2 does not include pip
by default, so you must install it manually.
Download the
get-pip.py
script for Python 2.7.console$ curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
Install
pip
for Python 2.console$ sudo python2.7 get-pip.py
Verify the installation.
console$ pip2.7 --version
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 confirm it works correctly.
Open the Python 2 shell.
console$ python2
Run a simple print statement.
python>>> print('Hello, World!')
Output:
Hello, World!
Exit the Python shell.
python>>> quit()
Conclusion
Python 2 is now installed alongside the default Python 3 environment on Ubuntu 22.04. This setup allows you to run legacy applications that require Python 2 while maintaining compatibility with modern tools.
For more details on legacy development, refer to the Python 2.7 documentation.
No comments yet.