How to Install Python 2 on Ubuntu 22.04
-
by cobra_admin
- 101
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.
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…
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…