Run these commands to ensure your repositories are up to date before installing

Copysudo apt update
sudo apt upgrade
sudo apt install python2.7

Then to install pip for python 2:

Copysudo apt install python-pip
Answer from Spiff on Stack Overflow
🌐
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

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
How do I install python 2.7
You don't. Nobody ships it anymore. It's unmaintained and is a security risk. Find an alternative in Python 3 or another language. There are libraries and tools to convert to Python 3, use those. Become a better Python programmer and do it yourself. Otherwise you can install a VM of an old Linux release like Ubuntu 18.04 and try it there. Keep it off the internet and away from your personal files. More on reddit.com
🌐 r/linuxquestions
21
0
November 23, 2023
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
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
🌐
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!
Top answer
1 of 5
21

Python 2 is no longer installed by default in fresh installations of Ubuntu 18.04 and later. Don't remove python3 from Ubuntu 18.04 and later or else Ubuntu Software, the terminal and many other apps that are installed by default will stop working. If you removed Python 3 and now Ubuntu Software, terminal and other applications don't work follow the instructions in this answer to reinstall it and get all applications working again.

To install Python 2.7 in Ubuntu 18.04 and later open the terminal and type:

sudo apt install python2.7  

To start the Python 2.7 interpreter run this command:

python2.7

To start the Python 3 interpreter run this command:

python3  

Either way the Python interpreter will show a version message when it is started that shows what version of Python you are running.

2 of 5
7

1) To install Python 2 version on Ubuntu 18.04 open up terminal and enter:

sudo apt install python-minimal

or

sudo apt install python2.7

Check version:

python --version


2) If still python 3+ updated list of Python alternatives to perform a switch between any python version is to run:

update-alternatives --config python

Example:

There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.5   2         auto mode
  1            /usr/bin/python2.7   1         manual mode
  2            /usr/bin/python3.5   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in manual mode

and select an appropriate version using selction integer as shown above.


3) If you see: update-alternatives: error: no alternatives for python. Run:

ls /usr/bin/python*

Example output:

/usr/bin/python  /usr/bin/python2  /usr/bin/python2.7  /usr/bin/python3  /usr/bin/python3.5

Next, update the Python alternatives list for each version you whish to use with priority 1 and 2:

update-alternatives --install /usr/bin/python python /usr/bin/python3.5 1
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2

Then run again update-alternatives --config python and select an appropriate version..

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.

🌐
Reddit
reddit.com › r/linuxquestions › how do i install python 2.7
r/linuxquestions on Reddit: How do I install python 2.7
November 23, 2023 - Yes, 18.04 is the last Ubuntu with Python 2. That's why I suggested it. ... Maybe you can still download it from python.org and build a pip env, that would be the most lightweight option. There are also probably python2 base container images that you can download from docker, etc. This said, running a python2 only project nowadays sounds like both obsolete and risky, you might want to isolate that properly ... Install an old distro.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › python 2.7.18 is installed yet only python 2.7.17 only shows up with python2 -v
r/learnpython on Reddit: Python 2.7.18 is installed yet only Python 2.7.17 only shows up with Python2 -V
February 15, 2022 -

Hi everyone,

I'm using a laptop with Ubuntu and I have just installed Python 2.7.18 using this tutorial https://tecadmin.net/install-python-2-7-on-ubuntu-and-linuxmint/ . When I execute Python2 -V, it shows me Python 2.7.17 as the version of Python installed. However, if I execute Python2.7 -V, it shows me Python 2.7.18 as the Python version (see screenshot drive link to see the issue). What does this mean? In my (other) Windows laptop, when I execute Python2 -V, it shows me Python 2.7.18 so why doesn't it happen here in my Ubuntu laptop? Thanks in advance.

Screenshot link: https://drive.google.com/file/d/18xlyZU8eEjBb4U90RwLq8g_oKUxCO_ud/view?usp=sharing

🌐
Ubuntu
launchpad.net › ubuntu › +source › python2.7
python2.7 package : Ubuntu - Launchpad
The following unsupported and untrusted Personal Archives (PPAs) provide packages of 'python2.7': Toolchain builds owned by PPA for Ubuntu Toolchain Uploads (restricted) Versions: Trusty (2.7.12-1~14.02), Bionic (2.7.18-1~18.04.1)
🌐
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 - curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py sudo python2.7 get-pip.py pip2 install virtualenv ... Now any python or pip command will point to Python 2.7 inside this environment.
🌐
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 - Once done with the above command, it is time to install the Python 2.7 version on Ubuntu Linux, for that, follow this syntax: sudo apt install python2-minimal · Check Python2 version · To view the current version of Python on your system run: ...
🌐
LinuxShout
linux.how2shout.com › home › how to install python 2.7 on ubuntu 24.04 noble lts linux
How to install Python 2.7 on Ubuntu 24.04 Noble LTS Linux - LinuxShout
June 18, 2024 - wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz ... After extracting, first switch to the extracted directory, and then follow the given procedure to compile the source code.
🌐
Ubuntu
launchpad.net › ubuntu › +source › python2.7 › 2.7.18-1~20.04.7
python2.7 2.7.18-1~20.04.7 source package in Ubuntu
* What's New in Python2.7 * Tutorial * Python Library Reference * Macintosh Module Reference * Python Language Reference * Extending and Embedding Python * Python/C API Reference * Installing Python Modules * Documenting Python * Distributing Python Modules · python2.7-examples: Examples for the Python language (v2.7) Examples, Demos and Tools for Python (v2.7). These are files included in the upstream Python distribution (v2.7). python2.7-minimal: Minimal subset of the Python language (version 2.7)
🌐
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 - The steps given here can be used for the previous versions of Ubuntu such as 18.04/20.04 including Debian, Linux Mint, elementary OS, PO_OS, and more… · It is necessary to perform the system update on Linux if you have not done this for a while. This not only installs the latest security updates but also refreshes the APT package manager cache. ... Even though Python 3 is the default version of Ubuntu 22.04 LTS, yet, Python 2.7 is available to install using the default system repository of Ubuntu.
🌐
GitHub
gist.github.com › iscle › 66e946553e74a883b4494d3b6df0ee82
Install python2.7 on Ubuntu 23.04 as "python" · GitHub
Install python2.7 on Ubuntu 23.04 as "python". GitHub Gist: instantly share code, notes, and snippets.
🌐
Python
docs.python.org › 2 › installing › index.html
Installing Python Modules — Python 2.7.18 documentation
July 19, 2020 - python2 -m pip install SomePackage # default Python 2 python2.7 -m pip install SomePackage # specifically Python 2.7 python3 -m pip install SomePackage # default Python 3 python3.4 -m pip install SomePackage # specifically Python 3.4
🌐
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!

🌐
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 - wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz · Once the file has been downloaded, here is how you extract and compile it: ... Since Python 2.7 is deprecated, setting up pip for it on Ubuntu 24.04 requires a manual installation process.