11

I need to install python 3.8.10 in a container running ubuntu 16.04.

16.04 has no support anymore, so I need a way to install it there manually.

Gulzar
  • 23,452
  • 27
  • 113
  • 201

1 Answers1

15

This follows from here

Add the following to your dockerfile, and change the python version as needed.

When the docker is up, python3.8 will be available in /usr/local/bin/python3.8

# compile python from source - avoid unsupported library problems
RUN apt update -y && sudo apt upgrade -y && \
    apt-get install -y wget build-essential checkinstall  libreadline-gplv2-dev  libncursesw5-dev  libssl-dev  libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev && \
    cd /usr/src && \
    sudo wget https://www.python.org/ftp/python/3.8.10/Python-3.8.10.tgz && \
    sudo tar xzf Python-3.8.10.tgz && \
    cd Python-3.8.10 && \
    sudo ./configure --enable-optimizations && \
    sudo make altinstall

Please note the following (standard [and quicker] way of installing) does not work for old ubuntu versions, due to end of support

RUN apt-get update && \
    apt-get install -y software-properties-common && \
    add-apt-repository -y ppa:deadsnakes/ppa && \
    apt-get update && \
    apt install -y python3.8

See also this to install into /usr/bin

Gulzar
  • 23,452
  • 27
  • 113
  • 201
  • If you're doing this in a Dockerfile, you probably want `make install`, not `make altinstall` as `altinstall` does not change paths or install it to a bin folder referred in usual default paths. `install` vs `altinstall` - https://stackoverflow.com/a/70513790/802203 – Ani Jan 27 '23 at 19:21