python2.7 version 2.7.18 is available in the Ubuntu 22.04 default repositories. Ubuntu 22.04 is the last LTS version of Ubuntu that contains this package in its default repositories. The phrase "I installed the new Ubuntu 22.04" in your question worries me because the newest Ubuntu LTS is not Ubuntu 22.04; it's Ubuntu 24.04. Please run lsb_release -a to confirm what version of Ubuntu you are using.

The expected results of lsb_release -a are:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.5 LTS
Release:    22.04
Codename:   jammy

To install python2.7 in Ubuntu 22.04 open the terminal and type:

sudo apt update  
sudo apt install python2.7  

Ubuntu 24.04

To install the python2.7 package from the Ubuntu 22.04 default repositories in Ubuntu 24.04 open the terminal and type:

sudo apt update
wget http://security.ubuntu.com/ubuntu/pool/universe/p/python2.7/python2.7_2.7.18-13ubuntu1.5_amd64.deb http://security.ubuntu.com/ubuntu/pool/universe/p/python2.7/libpython2.7-stdlib_2.7.18-13ubuntu1.5_amd64.deb http://security.ubuntu.com/ubuntu/pool/universe/p/python2.7/python2.7-minimal_2.7.18-13ubuntu1.5_amd64.deb http://security.ubuntu.com/ubuntu/pool/universe/p/python2.7/libpython2.7-minimal_2.7.18-13ubuntu1.5_amd64.deb  
sudo apt install ./libpython2.7-minimal_2.7.18-13ubuntu1.5_amd64.deb ./libpython2.7-stdlib_2.7.18-13ubuntu1.5_amd64.deb ./python2.7-minimal_2.7.18-13ubuntu1.5_amd64.deb ./python2.7_2.7.18-13ubuntu1.5_amd64.deb
Answer from karel on askubuntu.com
๐ŸŒ
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 ...
Discussions

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
When can we expect Python 3.10 in Anaconda?

It was added to the conda-forge channel 7 hours ago. You can install it with

conda install -c conda-forge python=3.10
More on reddit.com
๐ŸŒ r/Python
13
13
October 5, 2021
Python Package Installation though WSL ?
IMPORTANT NOTE: NEVER EDIT WSL FILES FROM WINDOWS, YOU WILL DESTROY YOUR WSL ENVIRONMENT AND REQUIRE RE-INSTALLING IT If you are wondering what the windows path is, thats going to be specific to your WSL environment and how you installed the package (as u/skeeto said) If you still have a Legacy ubuntu setup, its at %LOCALAPPDATA%\lxss\ If you installed from the microsoft store, your packages are installed to %LOCALAPPDATA%\Packages Inside wsl (assuming python3.6, cause don't use python 2 anymore), it will either be /usr/local/lib/python3.6/site-packages/, or if you use pip install --user, /home/$USER/.local/lib/python3.6/site-packages/ with scripts linked to /home/$USER/.local/bin/. Virtualenvs will be where you placed them, and have a similar folder structure. These will not be accessible from Windows, and if you want to run python code inside windows you will need to install Python for windows itself, and install your packages there. If you do pip install --user, your ~/.local/lib path will be available in the normal python interpreter inside WSL, so you can just pip install --user bs4 then start using BeautifulSoup without a problem. Unless your python is linux specific, I would still recommend running it in windows or a virtual machine if it is IO heavy, lots of file reads/writes or network traffic, as IO is still very slow inside WSL More on reddit.com
๐ŸŒ r/bashonubuntuonwindows
13
8
March 10, 2018
Python dev env setup in WSL2
I believe you can install the remote wsl extension for vs code and then directly try to run the code from command prompt inside vs code. More on reddit.com
๐ŸŒ r/bashonubuntuonwindows
8
7
June 29, 2020
๐ŸŒ
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
./configure --prefix=/usr/local/python2.7 make sudo make install ยท Option 2: Optimized Build (For potential performance gains) The --enable-optimizations flag enables Profile-Guided Optimization (PGO), which can result in a slightly faster ...
Starred by 31 users
Forked by 6 users
๐ŸŒ
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 - Learn how to install Python 2 on Ubuntu 20.04 and set it as default. Follow step-by-step instructions for a seamless setup process.
๐ŸŒ
LinuxConfig
linuxconfig.org โ€บ home โ€บ how to install python2 on ubuntu 26.04
How to Install Python2 on Ubuntu 26.04
March 22, 2026 - TL;DRPython 2 is not available in Ubuntu 26.04 repositories. Install using pyenv with the C11 flag to avoid compilation errors. ... Python 2 is end-of-life and poses significant security risks.
๐ŸŒ
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 - If you're using FreeBSD instead, check out how to install Python 2 on FreeBSD 14. SSH to your Ubuntu 20.04 server and install Python 2 with apt.
๐ŸŒ
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 - This article shows how to install Python 2 on Ubuntu 22.04, set up pip for Python 2, and verify the installation.
Find elsewhere
๐ŸŒ
Greenwebpage
greenwebpage.com โ€บ home โ€บ blog โ€บ how to install python 2 on ubuntu 24.04: 3 quick methods
How to Install Python 2 on Ubuntu 24.04: 3 Quick Methods
April 3, 2025 - This guide walks you through installing Python 2 on Ubuntu 24.04, from compiling the source code and setting up pip.
๐ŸŒ
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 - Learn how to install Python 2 on Ubuntu 22.04. Follow step-by-step instructions to set it as the default Python interpreter.
๐ŸŒ
Centron
centron.de โ€บ startseite โ€บ install python 2 on ubuntu 22.04 with pip setup
Install Python 2 on Ubuntu 22.04 with pip Setup
August 18, 2025 - Learn how to install Python 2 on Ubuntu 22.04, set up pip, and run legacy applications with Python 2.7.18 using official repositories.
๐ŸŒ
LinuxVox
linuxvox.com โ€บ blog โ€บ install-python-2-ubuntu
Installing Python 2 on Ubuntu: A Comprehensive Guide โ€” linuxvox.com
Ubuntu uses apt (Advanced Package Tool) as its package management system. When you install Python 2, you are essentially asking apt to download and set up the necessary software packages from Ubuntu's official repositories.
๐ŸŒ
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 - Learn how to install Python 2 on Ubuntu 18.04 using a simple command. Verify Python versions and manage packages easily. Read more now!
๐ŸŒ
Kbmisc
kbmisc.com โ€บ blog โ€บ install-python-on-ubuntu
How to Install Python 3 or Python 2 on Ubuntu 20.04 - Blog
See how to install Python 2.7 and/or Python 3 on Ubuntu 20.04 Linux via the command line with step by step instructions.
๐ŸŒ
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
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1 $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
๐ŸŒ
The Hitchhiker's Guide to Python
docs.python-guide.org โ€บ starting โ€บ install โ€บ linux
Installing Python 2 on Linux โ€” The Hitchhiker's Guide to Python
Check out our guide for installing Python 3 on Linux. The latest versions of CentOS, Red Hat Enterprise Linux (RHEL) and Ubuntu come with Python 2.7 out of the box.
๐ŸŒ
Linux Hint
linuxhint.com โ€บ install-python-2-ubuntu
How to Install Python 2 on Ubuntu โ€“ Linux Hint
[adthrive-in-post-video-player video-id=โ€v7gsM3L3โ€ณ upload-date=โ€2023-02-09T12:49:26.000Zโ€ name=โ€How to Install Python 2 on Ubuntuโ€ description=โ€How to Install Python 2 on Ubuntuโ€ player-type=โ€collapseโ€ override-embed=โ€trueโ€] According to the official reports from developers of Python, Python 2 has been completely removed from Ubuntu 20.4, and its default version is not installed on Ubuntu.
๐ŸŒ
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!

๐ŸŒ
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 - Learn to install Python 2.7 on Ubuntu, Debian & Linux Mint. Our guide covers the full process, ensuring a secure setup for legacy applications.
Top answer
1 of 2
2

There are several options to install Python interpreters without messing up the system. If you're comfortable with Docker, the best option would probably be to use a Python2 Docker container. A Docker container is somewhat similar to a VM, it's an isolated environment on your system, but much more lightweight. When starting the container, you can mount the path of your code into the container and then work from within it without affecting your system. Example (using the Docker image suggested by Artur Meinild in the comments):

docker run --rm -itd -v/path/to/code:/code -w /code --name my-python2-env esolang/python2
docker exec -it my-python2-env bash  # this will start a shell within the container
docker stop my-python2-env  # stop the container when you don't need it anymore

Another method would be to use anaconda or miniconda. This software allows you to install and manage several Python environments distinct from your system's interpreter. It's like Pip, but much more capable, e.g., it can also install interpreters and even non-Python libraries like CUDA with a simple conda install command. For instructions on how to install Conda, please refer to the official documentation.

You could also install Python2 from source into your home directory (or some other non-system directory). But this method is probably more complicated than the other two solutions and would require you to also install other dependencies from source into a non-system directory as well.

2 of 2
1

I used miniconda as suggested by Green and here's the breakdown of the steps I took to setup a conda environment using python 2.7.

  1. Install miniconda:open this link, select Linux and follow the instructions. Once you install miniconda (or anaconda) your prompt changes to show which conda environment is active (base by default) CLI prompt with base conda environment active

  2. Create a new conda environment using python 2.7:

    conda create -n py27 python=2.7 where py27 is the name of the virtual environment.

  3. Activate the py27 virtual environment.

    conda activate py27

    The prompt changes to show py27 instead of base. Py27 environment activated.

    You're all set up. Now when you run python command in the terminal you'll be executing python 2.7.x. Python 2.7.16 in my case.

Note: whenever you open a new terminal, conda environment will be set to base. If you want to remove the py27 environment, run conda env remove --name py27.

๐ŸŒ
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 - The above command will download the Python2 last version (2.7.15). ... To manage the Python packages we need to install pip.