Ubuntu 18.04

apt-add-repository -y ppa:deadsnakes
apt update
apt install python3.8

export VERSION=3.10.14
sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
wget https://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tgz
tar -xf Python-${VERSION}.tgz
cd Python-${VERSION}
make -j $(nproc)
sudo make altinstall