This simple copy paste tutorial will allow you to install any version of Python.
Install python 2, all the way up to python 3.9+
You can select any version from this list: https://www.python.org/ftp/python/
I highly recommend using pipenv instead of installing python locally on any OS:
Works on ANY Ubuntu 16, 17, 18, 19, 20+
Using pipenv (highly, highly recommended!)
sudo apt update -y sudo apt install python pipenv git -y git clone https://github.com/pyenv/pyenv.git ~/.pyenv echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH"
Now you can install any version of Python with pyenv and pipenv
pyenv install 3.9-dev cd /home/my/project pipenv --python 3.9 pipenv shell # pipenv run pip install -r requirements.txt # pipenv run python manage.py
Force Installing on Ubuntu
# choose your version py_version=3.8.4 sudo apt update -y sudo apt install build-essential gcc autoconf make automake \ wget libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev \ libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev libffi-dev uuid-dev -y wget https://www.python.org/ftp/python/${py_version}/Python-${py_version}.tgz tar xzf Python-${py_version}.tgz cd Python-${py_version} sudo ./configure --enable-optimizations sudo make altinstall export PATH=/opt/python-${py_version}/bin:$PATH which python3.8 python3.8 --version
Looking for the CentOS version? See CentOS version.
Install Python 3.x in a Dockerfile
# choose your version ENV py_version=3.8.4 WORKDIR /root/ RUN apt update -y RUN apt install build-essential gcc autoconf make automake \ wget libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev \ libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev libffi-dev uuid-dev -y RUN wget https://www.python.org/ftp/python/${py_version}/Python-${py_version}.tgz RUN tar xzf Python-${py_version}.tgz WORKDIR Python-${py_version} RUN ./configure --enable-optimizations RUN make altinstall RUN export PATH=/opt/python-${py_version}/bin:$PATH RUN which python3.8 RUN python3.8 --version