Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install python specific version on docker?

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.

like image 491
Gulzar Avatar asked Dec 14 '25 17:12

Gulzar


1 Answers

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

like image 200
Gulzar Avatar answered Dec 17 '25 11:12

Gulzar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!