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 ·...
Discussions

Need to install python 2. How do I accomplish this?
If you're in need of multiple different languages being installed, I've very much enjoyed using the tool "mise". It's a language env manager. If you install mise, you can use it to manage your different language installs. mise use python@2.x.y.z This would install and use Python with that version globally. More on reddit.com
🌐 r/linuxmint
18
0
March 23, 2025
What is the safest way to work with Python 2 on Ubuntu 24.04?
Containerisation if left up to me More on reddit.com
🌐 r/learnpython
18
12
August 7, 2024
apt - How to install python2.7-dev package on vanilla debian 12? - Unix & Linux Stack Exchange
I searched in my repo but couldn't find the "python2.7-dev" to install some previously built old packages by building and installing from GitHub repo. Is there a way to sideload it? 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
🌐
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 ...
🌐
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 ... tar -xvf Python-2.7.18.tgz cd Python-2.7.18 ./configure --enable-optimizations ...
🌐
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
🌐
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
Find elsewhere
🌐
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.
🌐
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 ...
🌐
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.
🌐
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 install python2-minimal · Check Python2 version · To view the current version of Python on your system run: python2 -V · Output: Python 2.7.18 · As we know Ubuntu 20.04 comes out of the box with Python 3 thus, let’s check what ...
🌐
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).
🌐
Reddit
reddit.com › r/learnpython › what is the safest way to work with python 2 on ubuntu 24.04?
r/learnpython on Reddit: What is the safest way to work with Python 2 on Ubuntu 24.04?
August 7, 2024 -

Hi all! I just started a new job that is having me analyze/write code in Python 2. The reason it is Python 2 and not Python 3 is because we are supporting older systems that require it, and our code must be backwards compatible with these systems.

With that said, the workstation they've supplied me is running Ubuntu 24.04, and I'm at wits end as to how I can SAFELY run Python 2 code on it. From what I've gathered, recent versions of Ubuntu depend on Python 3 packages so it isn't as simple as adding a legacy apt repo and installing Python 2 - it would break my OS.

So, the question remains: How can I safely work with Python 2 without bricking my OS? Do I need to containerize or use virtualization? Thank you!

🌐
Kbmisc
kbmisc.com › blog › install-python-on-ubuntu
How to Install Python 3 or Python 2 on Ubuntu 20.04 - Blog
$ sudo apt update $ sudo apt install python2 · Step 2. You can verify successful installation with this command: $ python2 --version Python 2.7.18 · Step 3. To use Python 2 as your default Python version, you can install the python-is-python2 package. $ sudo apt install python-is-python2 ·
🌐
LinuxConfig
linuxconfig.org › home › install python 2 on ubuntu 18.04 bionic beaver linux
Install Python 2 on Ubuntu 18.04 Bionic Beaver Linux
May 27, 2020 - Python version 3 is now the default python interpreter on Ubuntu 18.04 Desktop or Server release. However, if you need to install the older Python 2 version you can do that with a single apt command.
🌐
TecAdmin
tecadmin.net › install-python-2-7-on-ubuntu-and-linuxmint
How to Install Python 2.7 on Ubuntu, Debian & Linux Mint
April 26, 2025 - After running these commands, pip2 will be installed for Python 2.7. You can now start using Python 2.7 on your system. To ensure you’re using Python 2.7 specifically, use python2.7 or pip2 for installing Python 2 packages.
🌐
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.