After searching the Ubuntu packages, it seems that for some odd reason for Ubuntu 20.04 the name of the Python 2 package is python2 but for Ubuntu 18.04 there is no package named python2. It seems that for Ubuntu 18.04 by running:

sudo apt-get install python-pip

This installs both pip for Python 2 and Python 2 itself, so this seems to be the best option

Answer from cdahms on Stack Overflow
🌐
LinuxConfig
linuxconfig.org › home › install python 2 on ubuntu 20.04 focal fossa linux
Install Python 2 on Ubuntu 20.04 Focal Fossa Linux
June 17, 2022 - How to install Python2 Ubuntu 20.04 ... Ubuntu 20.04 open a terminal and enter the following commands: $ sudo apt update $ sudo apt install python2 ·...
🌐
Linux Hint
linuxhint.com › install-python-2-ubuntu
How to Install Python 2 on Ubuntu – Linux Hint
sudo apt install python2 · It will take your permission for confirmation. For this, press the Y and then Enter button to resume the download. Once the above command is executed, you can check your system’s currently installed Python version. To check its current version, execute the command ...
Discussions

python 2.x - Ubuntu 18.04 "sudo apt-get install python2" results in "E: Unable to locate package python2" - Stack Overflow
In preparation for supporting a Python 2 legacy application I just installed Ubuntu 18.04.5, which includes Python 3 but not Python 2. Pretty much every Python 2 install tutorial website shows the More on stackoverflow.com
🌐 stackoverflow.com
apt - How to install python2.7-dev package on vanilla debian 12? - Unix & Linux Stack Exchange
Run sudo apt update, and you will be able to install python2.7-dev. More on unix.stackexchange.com
🌐 unix.stackexchange.com
February 5, 2024
Is there any way to get Python 2 on Debian 12?
It is still possible, firstly open /etc/apt/sources.list and add this new line, which adds Debian 9 software to apt-get sources: deb http://archive.debian.org/debian/ stretch contrib main non-free then in bash type the following command: sudo apt-get update sudo apt-get install python2.7 Now you should be able to use python2.7 in Debian12. Don't forget to remove that new line in /etc/apt/sources.list,otherwise it may affect your future apt-get More on reddit.com
🌐 r/linuxquestions
17
2
January 30, 2024
Python 2.7.18 is installed yet only Python 2.7.17 only shows up with Python2 -V
Why on earth are you using the unsupported legacy Python instead of a recent version of Python 3? The last few versions of Ubuntu include Python 3, python3 myfile.py on command line. More on reddit.com
🌐 r/learnpython
12
0
February 15, 2022
🌐
LinuxConfig
linuxconfig.org › home › install python 2 on ubuntu 22.04 jammy jellyfish linux
Install Python 2 on Ubuntu 22.04 Jammy Jellyfish Linux
January 17, 2022 - $ sudo apt update $ sudo apt install python2 · Check your current Python version: $ python2 -V Python 2.7.17 · Follow our tutorial on how to switch to Python 2 from Python 3 as a default version on Ubuntu 22.04.
🌐
Vultr
docs.vultr.com › how-to-install-python-2-on-ubuntu-20-04
How to Install Python 2 on Ubuntu 20.04 Complete Guide | Vultr Docs
April 15, 2026 - SSH to your Ubuntu 20.04 server and install Python 2 with apt. ... Check the Python version. ... 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 ...
🌐
Medium
medium.com › @kallagoutham33 › how-to-install-python-2-on-ubuntu-24-04-12c0819278ba
How to install Python 2 on Ubuntu 24.04 | by Goutham Kalla | Medium
October 6, 2025 - sudo apt update sudo apt install build-essential checkinstall sudo apt install libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev · Step 2: Download the Python 2 Source Code · wget https://www.python.org/ft...
Find elsewhere
🌐
Medium
parathan.medium.com › how-to-install-python2-and-pip-on-ubuntu-20-04-fb3d9892f54c
How to install python2 and pip on Ubuntu 20.04 | by Parathan Thiyagalingam | Medium
March 21, 2022 - But somehow, some of the not evolving scripts which were written on Python2 needs to be executed with the help of Python2. sudo apt install python-minimal · The above command will download the Python2 last version (2.7.15).
🌐
The Hitchhiker's Guide to Python
docs.python-guide.org › starting › install › linux
Installing Python 2 on Linux — The Hitchhiker's Guide to Python
However, with the growing popularity of Python 3, some distributions, such as Fedora, don’t come with Python 2 pre-installed. You can install the python2 package with your distribution package manager:
🌐
LinuxConfig
linuxconfig.org › home › how to install python2 on ubuntu 26.04
How to Install Python2 on Ubuntu 26.04
March 22, 2026 - This method installs Python 2 system-wide to /usr/local/python2.7. Install build dependencies: Install the required development packages. $ sudo apt update $ sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev \ libreadline-dev ...
🌐
LinuxShout
linux.how2shout.com › home › how to install python 2.7 on ubuntu 20.04 lts
How to install Python 2.7 on Ubuntu 20.04 LTS - LinuxShout
June 18, 2024 - sudo apt update sudo apt install curl curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py sudo python2 get-pip.py
🌐
GitHub
github.com › ctch3ng › Installing-Python-2.7-and-pip-on-Ubuntu-24.04-Noble-LTS
GitHub - ctch3ng/Installing-Python-2.7-and-pip-on-Ubuntu-24.04-Noble-LTS · GitHub
However, if you need it for legacy applications, you can install it by compiling from source. Update and upgrade all system packages (YES to all): ... sudo apt install -y build-essential checkinstall libncurses-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev libreadline-dev libdb-dev
Starred by 31 users
Forked by 6 users
🌐
Hostry
help.hostry.com › knowledge-base › how-to-install-python-2-on-ubuntu-20-04
How to Install Python 2 on Ubuntu 20.04 – Hostry Help Center
Connect to your server Ubunt 20.04 and install Python 2 with apt. ... To do this, install alternatives to Python 2 and Python 3. $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1 $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
🌐
GitHub
gist.github.com › thejmazz › f25d801e1ddbcb458e5f
Install python 2.7.9 and 3.4.3 on Ubuntu - Gist - GitHub
$ apt install python2 git · Copy link · Copy Markdown · Amazing thank you! Copy link · Copy Markdown · This worked great! Thanks! Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment ·
Top answer
1 of 3
5

You can still install Python 2.7 from Debian 11. Mixing releases is typically decried as a bad idea, but that is mostly in the context of adding a newer release; adding an older (still-supported) release is much less error-prone, as long as you keep an eye on any packages apt wants to remove.

Add a file, /etc/apt/sources.list.d/bullseye.list, containing

deb http://deb.debian.org/debian bullseye main
deb http://deb.debian.org/debian bullseye-updates main
deb http://security.debian.org bullseye-security main

Run sudo apt update, and you will be able to install python2.7-dev.

As you are probably aware, maintaining Python 2-based projects is becoming increasingly difficult, and the above won’t be a viable approach once Debian 11 is no longer supported (some would argue it already isn’t viable).

2 of 3
1

The PPA Approach

While Stephen's answer is certainly viable until Bullseye is no longer supported. I believe this approach will survive until the various python versions are removed from the PPA. Adding this PPA or Personal Package Archive, or any for that matter is relatively easy.

The PPA Specifically for Python

The Dead Snakes Personal Package Archive contains packaged versions of Python all the way back to 2.3. Add it with: sudo add-apt-repository ppa:deadsnakes/ppa

Note that these are made to work with Ubuntu, and since that's a Debian derivative:

The packages may also work on other versions of Ubuntu or Debian, but that is not tested or supported.

See also: Install newer & older versions of python on debian?. Read Gilles' answer from 8 years ago that's still quite valid.

🌐
Vultr
docs.vultr.com › how-to-install-python-2-on-ubuntu-22-04
How to Install Python 2 on Ubuntu 22.04 Complete Guide | Vultr Docs
July 2, 2025 - Have access to an Ubuntu 22.04 instance as a non-root sudo user. 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. ... Install the required tools for managing repositories. ... Check the available version of Python 2 in the APT sources. ... python2...
🌐
GitHub
gist.github.com › iscle › 66e946553e74a883b4494d3b6df0ee82
Install python2.7 on Ubuntu 23.04 as "python" · GitHub
You won't be able to make a venv out of that unless you sudo apt-get install libssl-dev before installing ... Also, works for 24.04.2 LTS. Thanks ... Installing it as /usr/bin/python2 is fine.
🌐
FOSS Linux
fosslinux.com › home › programming › how to switch python versions on ubuntu 26.04 (2026)
How to Switch Python Versions on Ubuntu 26.04 (2026)
2 weeks ago - fosslinux@ubuntu:~$ sudo apt install python2 Reading package lists... Building dependency tree... Reading state information... Package python2 is not available, but is referred to by another package.