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
๐ŸŒ
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.
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
Python2.7 on Ubuntu 23.04
Python 2.7 is pretty old, I have transfered all my codes to Python 3, it has a higher performance, compatability etc. In your case, I would recommend to use conda (simply miniconda) and create a virtual environment with python=2.7, see conda instructions . I think it always good to isolate the environment from the global one from ubuntu, in order to not fuck up the latter More on reddit.com
๐ŸŒ r/Ubuntu
6
2
July 13, 2023
Installing Python 2.7 projects in a system with Python 3.10 - Stack Overflow
My company's projects are all based in Python 2.7 and use specific PATH and PYTHONPATH exports to get around each other. The new machine I received has Ubuntu 22.04 and Python 3.10 preinstalled. My previous used to have Python 2.7 and I just installed 3.x on top and it worked just fine, at ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - How to install Python2.7.5 in Ubuntu docker image? - Stack Overflow
I have specific requirement to install Python 2.7.5 in Ubuntu, I could install 2.7.18 without any issues Below is my dockerfile ARG UBUNTU_VERSION=18.04 FROM ubuntu:$UBUNTU_VERSION RUN apt-get upd... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
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 - This tutorial will show how to install Python 2 for Ubuntu 22.04 Jammy Jellyfish. Python 2 has not been the default installed version on Ubuntu versions for a few years, but itโ€™s still possible to install Python 2 and to install Python 2.7 on Ubuntu 22.04.
๐ŸŒ
NetsLovers
netslovers.com โ€บ home โ€บ tutorials โ€บ how to install python 2.7 and pip on ubuntu 22.04 lts?
How To Install Python 2.7 And PIP On Ubuntu 22.04 LTS?
October 24, 2023 - It seems we have Python 3.10 too, so will do the following steps to make our preferred version Python 2.7 the system default one. # sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1 # sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
๐ŸŒ
LinuxShout
linux.how2shout.com โ€บ home โ€บ how to install python 2 on ubuntu 22.04 lts jammy linux
How to Install Python 2 on Ubuntu 22.04 LTS Jammy Linux - LinuxShout
May 7, 2022 - Get the easy steps to install Python2 or 2.7 on Ubuntu 22.04 LTS Jammy JellyFish using the command terminal to run old applications that need this version. Python is an object-oriented programming โ€ฆ
๐ŸŒ
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 - Download the get-pip.py script for Python 2.7. ... Install pip for Python 2. ... Verify the installation. ... After installation, test the Python 2 interpreter to confirm it works correctly.
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/ubuntu โ€บ python2.7 on ubuntu 23.04
r/Ubuntu on Reddit: Python2.7 on Ubuntu 23.04
July 13, 2023 -

HI! I recently change my system from Ubuntu 22.04 to Ubuntu 23.04 because I built a new computer and had some trouble getting my system to run on the older kernel. Last week i tried to work on a project from work and i notice python 2 is not installed out of the box, tried to install it from the official Ubuntu repo with apt but found out it is not available anymore. Also tried to compile it from source with no luck either since tons of decencies are missing. Has anyone here manage to install Python2.7 on their machine? If so, could you help me?

๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 75181965 โ€บ installing-python-2-7-projects-in-a-system-with-python-3-10
Installing Python 2.7 projects in a system with Python 3.10 - Stack Overflow
My company's projects are all based in Python 2.7 and use specific PATH and PYTHONPATH exports to get around each other. The new machine I received has Ubuntu 22.04 and Python 3.10 preinstalled. My previous used to have Python 2.7 and I just installed 3.x on top and it worked just fine, at ...
๐ŸŒ
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 - Thus, we changed the priority and set Python2 at the top so that it could be called by applications as the default version. Whereas Python3 will be second. 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
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
This can avoid overwriting or conflicting with files belonging to the system's default Python 3 installation, potentially breaking system utilities that rely on Python 3. ./configure --prefix=/usr/local/python2.7 make sudo make install
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 - This tutorial will show how to install Python2 for Ubuntu 20.04 Focal Fossa Linux. Python 2 has not been the default installed version on Ubuntu for a few years, but itโ€™s still possible to install Python2 and to install Python 2.7 on Ubuntu.
๐ŸŒ
GitHub
gist.github.com โ€บ CynicRus โ€บ 5a2bd5a06a699cd0139aaff887f5cab5
build python2 on ubuntu 22.04 ยท GitHub
build python2 on ubuntu 22.04. GitHub Gist: instantly share code, notes, and snippets.
Top answer
1 of 3
11

This version is no longer available in canonical mirrors.

It has been released in 2013.

As a result, having both python and pip working together since then is challenging.

Python 2.7.5 + PIP on centos7

It may be the simplest way if ubuntu is not a requirement.

CopyARG CENTOS_VERSION=7
FROM centos:$CENTOS_VERSION

# Python 2.7.5 is installed with centos7 image
# Add repository for PIP
RUN yum install -y epel-release

# Install pip
RUN yum install -y python-pip

RUN python --version

ENTRYPOINT [ "python" ]

Python 2.7.5 on ubuntu

I've been able to install it from source

It has not been a success to install pip :

https://bootstrap.pypa.io/pip/2.7/get-pip.py

CopyARG UBUNTU_VERSION=18.04
FROM ubuntu:$UBUNTU_VERSION

ARG PYTHON_VERSION=2.7.5

# Install dependencies
# PIP - openssl version > 1.1 may be an issue (try older ubuntu images)
RUN apt-get update \
  && apt-get install -y wget gcc make openssl libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev \
  && apt-get clean

WORKDIR /tmp/

# Build Python from source
RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \
  && tar --extract -f Python-$PYTHON_VERSION.tgz \
  && cd ./Python-$PYTHON_VERSION/ \
  && ./configure --enable-optimizations --prefix=/usr/local \
  && make && make install \
  && cd ../ \
  && rm -r ./Python-$PYTHON_VERSION*

RUN python --version

ENTRYPOINT [ "python" ]

Python 2.7.6 + pip on ubuntu

Ubuntu 14.04 still has mirrors working (how long ???).

Python packages are really close to your expectations.

You may try to run your scripts with that one.

CopyARG UBUNTU_VERSION=14.04
FROM ubuntu:$UBUNTU_VERSION

RUN apt-get update \
  && apt-get install -y python python-pip \
  && apt-get clean

RUN python --version

ENTRYPOINT [ "python" ]

Python 2.7.5 + pip, not working but could on ubuntu

Here is what I've tried with no success.

CopyARG UBUNTU_VERSION=16.04
FROM ubuntu:$UBUNTU_VERSION


# Install dependencies
RUN apt-get update \
  && apt-get install -y wget gcc make openssl libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev \
  && apt-get clean

WORKDIR /tmp/

# Build python from source
RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \
  && tar --extract -f Python-$PYTHON_VERSION.tgz \
  && cd ./Python-$PYTHON_VERSION/ \
  && ./configure --enable-optimizations --prefix=/usr/local \
  && make && make install \
  && cd ../ \
  && rm -r ./Python-$PYTHON_VERSION*

# Build pip from source
RUN wget https://bootstrap.pypa.io/pip/2.7/get-pip.py \
    && python get-pip.py

RUN python --version

ENTRYPOINT [ "python" ]

Python 2.7.9 with pip - as requested in comment

You can use this dockerfile, building python includes pip.

CopyARG UBUNTU_VERSION=16.04
FROM ubuntu:$UBUNTU_VERSION

ARG PYTHON_VERSION=2.7.9

# Install dependencies
RUN apt-get update \
  && apt-get install -y wget gcc make openssl libffi-dev libgdbm-dev libsqlite3-dev libssl-dev zlib1g-dev \
  && apt-get clean

WORKDIR /tmp/

# Build Python from source
RUN wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz \
  && tar --extract -f Python-$PYTHON_VERSION.tgz \
  && cd ./Python-$PYTHON_VERSION/ \
  && ./configure --with-ensurepip=install --enable-optimizations --prefix=/usr/local \
  && make && make install \
  && cd ../ \
  && rm -r ./Python-$PYTHON_VERSION*

RUN python --version \
  && pip --version

ENTRYPOINT [ "python" ]
2 of 3
1

The simplest possible solution:

Copysudo apt-get install libssl-dev openssl
wget https://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz
tar xzvf Python-2.7.5.tgz
cd Python-2.7.5
./configure
make
sudo make install

After installation completed set installed python as default one.

๐ŸŒ
How2Shout
how2shout.com โ€บ home โ€บ how to install python 2.7 & pip2 on ubuntu 20.04 lts linux
How to install Python 2.7 & PIP2 on Ubuntu 20.04 LTS Linux - LinuxShout
April 23, 2021 - Well, to set the default one, we need to assign priority to different versions of Python language available on our Ubuntu system. For that first set alternative versions for Python. For example, I have two versions on my systems, one is 2.7, and the other is 3.8. Thus, I am setting 2.7 as the default version by giving it priority 1 and 2 to 3.8 one. update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2
Top answer
1 of 7
108

I did it with pythonbrew on my Ubuntu 10.10 machine.

$ python -V
Python 2.6.6
$ curl -kL https://raw.github.com/utahta/pythonbrew/master/pythonbrew-install | bash
$ . $HOME/.pythonbrew/etc/bashrc
$ pythonbrew install 2.7.1
$ pythonbrew switch 2.7.1
Switched to Python-2.7.1
$ python -V
Python 2.7.1

I also used it to install Python 3.2.

2 of 7
10

I recently backported Python 2.7 to Debian squeeze. Since Ubuntu 10.10 is newer than Debian squeeze, if you can do it on squeeze, you can certainly do it on Ubuntu. I don't have access to a Ubuntu 10.10 system. If I set one up, I'll test on it, and update this answer. So, here instead is a brief sketch of what I did on Debian.

First, a general and obvious comment, but something that is easily overlooked. One should not take the listed build dependencies of a Debian package too seriously. They may be far more specific than needed. For example, software like Python, which is designed to be portable and run over a wide array of systems, is unlikely to build depend on very specific versions of software. The runtime dependencies can be adjusted as well, but this should be done with more caution. However, runtime dependencies are mostly generated dynamically based on software that is already on this system, so usually that is not a big issue.

apt-cache policy python2.7
python2.7:
  Installed: 2.7.2-8
  Candidate: 2.7.2-8
  Version table:
     2.7.2-12 0
         50 http://debian.csail.mit.edu/debian/ unstable/main i386 Packages
     2.7.2-8 0
         50 http://debian.csail.mit.edu/debian/ testing/main i386 Packages
 *** 2.7.2-8 0
        100 /var/lib/dpkg/status

Selecting the testing version we get

apt-get source python2.7=2.7.2-8

Looking at debian/control, we see the following build dependency lines.

Build-Depends: debhelper (>= 5), quilt, autoconf, libreadline-dev, libtinfo-dev, libncursesw5-dev (>= 5.3), tk8.5-dev, zlib1g-dev, blt-dev (>= 2.4z), libssl-dev, libexpat1-dev, sharutils, libbz2-dev, libbluetooth-dev [linux-any], locales [!armel !avr32 !hppa !ia64 !mipsel], libsqlite3-dev, libffi-dev (>= 3.0.5), mime-support, libgpm2 [linux-any], netbase, lsb-release, bzip2, libdb4.8-dev, gdb, python, help2man Build-Depends-Indep: python-sphinx Build-Conflicts: tcl8.3-dev, tk8.3-dev, tcl8.4-dev, tk8.4-dev, python2.7-xml, python-xml, autoconf2.13, libncurses5-dev

Most of this is easily satisfied on squeeze. With the handy utility apt-show-versions we get on my machine

apt-show-versions debhelper quilt autoconf libreadline-dev libtinfo-dev libncursesw5-dev tk8.5-dev zlib1g-dev blt-dev \
libssl-dev libexpat1-dev sharutils libbz2-dev libbluetooth-dev locales libsqlite3-dev \
libffi-dev mime-support libgpm2 netbase lsb-release bzip2 libdb4.8-dev gdb python help2man python-sphinx

autoconf/squeeze uptodate 2.67-2
blt-dev/squeeze uptodate 2.4z-4.2
bzip2/squeeze uptodate 1.0.5-6
debhelper/squeeze-backports uptodate 8.9.13~bpo60+1
gdb/squeeze uptodate 7.0.1-2+b1
help2man/squeeze uptodate 1.38.2
libbluetooth-dev/squeeze uptodate 4.66-3
libbz2-dev/squeeze uptodate 1.0.5-6
libdb4.8-dev/squeeze uptodate 4.8.30-2
libexpat1-dev/squeeze uptodate 2.0.1-7
libffi-dev/squeeze uptodate 3.0.9-3
libgpm2/squeeze uptodate 1.20.4-3.3
libncursesw5-dev/squeeze uptodate 5.7+20100313-5
libreadline-dev/squeeze uptodate 6.1-3
libsqlite3-dev/squeeze uptodate 3.7.3-1
libssl-dev/squeeze uptodate 0.9.8o-4squeeze5
libtinfo-dev not installed
locales/squeeze uptodate 2.11.2-10
lsb-release/squeeze uptodate 3.2-23.2squeeze1
mime-support/squeeze uptodate 3.48-1
netbase/squeeze uptodate 4.45
python/squeeze uptodate 2.6.6-3+squeeze6
python-sphinx/squeeze-backports uptodate 1.0.8+dfsg-2~bpo60+1
quilt/squeeze uptodate 0.48-7
sharutils/squeeze uptodate 1:4.9-1
tk8.5-dev/squeeze uptodate 8.5.8-1
zlib1g-dev/squeeze uptodate 1:1.2.3.4.dfsg-3

We see that everything except libtinfo-dev is available in squeeze. I do have the squeeze backport versions of debhelper and python-sphinx, but both of these are also available for debian squeeze in versions satisfying the build requirements.

Observe also that I have libncurses5-dev installed

apt-show-versions libncurses5-dev

libncurses5-dev/squeeze uptodate 5.7+20100313-5

Both of these packages correspond to the source package curses 5.7+20100313-5. Observe that libtinfo-dev in fact replaces libncurses5-dev.

apt-cache show libtinfo-dev

Package: libtinfo-dev
Source: ncurses
Version: 5.9-4
Installed-Size: 279
Maintainer: Craig Small <[email protected]>
Architecture: i386
Replaces: libncurses5-dev (<< 5.9-3)
Depends: libtinfo5 (= 5.9-4)

One would not expect python 2.7 to develop on such a specific version of curses, and in fact it doesn't. However, if you try to build the packages without satisfying the dependency you get

debuild -uc -us

dpkg-checkbuilddeps: Unmet build dependencies: libtinfo-dev
dpkg-checkbuilddeps: Build conflicts: libncurses5-dev
debuild: fatal error at line 1289:
You do not appear to have all build dependencies properly met.
You can use mk-build-deps to generate a dummy package which
Depends on all the required packages, or you can install them
manually using dpkg or apt using the error messages just above
this message.

So, it is necessary to edit debian/control. Note that you also need to similarly edit the file debian/control.in, otherwise the control file will be incorrectly regenerated from control.in. The simplest thing to do is just remove libncurses5-dev from the Build-Conflicts line and libtinfo-dev from the Build-Depends line, and then run debuild -uc -us again. If you are going to have this package installed alongside the standard default Python 2.6 packages on Debian squeeze, you also need to remove the two lines

Conflicts: python-profiler (<= 2.7.1-2)
Replaces: python-profiler (<= 2.7.1-2)

Those lines are there because 2.7 includes the python-profiler functionality. If 2.7 is the default python, then python-profiler is no longer necessary. However, if one is installing 2.7 as a non-default Python, that reasoning does not apply, and python-profiler is still needed by 2.6.

This should build successfully, and result in the following list of binary packages.

ls -lah *.deb

-rw-r--r-- 1 faheem staff 289K Jan 12 02:33 idle-python2.7_2.7.2-8_all.deb
-rw-r--r-- 1 faheem staff 1.1M Jan 12 02:34 libpython2.7_2.7.2-8_i386.deb
-rw-r--r-- 1 faheem staff 2.5M Jan 12 02:34 python2.7_2.7.2-8_i386.deb
-rw-r--r-- 1 faheem staff  12M Jan 12 02:34 python2.7-dbg_2.7.2-8_i386.deb
-rw-r--r-- 1 faheem staff 4.9M Jan 12 02:34 python2.7-dev_2.7.2-8_i386.deb
-rw-r--r-- 1 faheem staff 6.0M Jan 12 02:33 python2.7-doc_2.7.2-8_all.deb
-rw-r--r-- 1 faheem staff 692K Jan 12 02:33 python2.7-examples_2.7.2-8_all.deb
-rw-r--r-- 1 faheem staff 1.7M Jan 12 02:34 python2.7-minimal_2.7.2-8_i386.deb

Finally, one can install the binary packages with

dpkg -i python2.7-minimal_2.7.2-8_i386.deb python2.7_2.7.2-8_i386.deb python2.7-dev_2.7.2-8_i386.deb libpython2.7_2.7.2-8_i386.deb 

Sometimes dpkg can be a little difficult about satisfying dependencies when they are all installed at once, so you might have to run apt-get -f install afterwards if you get dependency errors, or alternatively install the packages in smaller groups.