Initial Setup of a Ubuntu 20.04 VM with Compiled Python 3.10

Assuming you have logged in as root with a password

Creating a non-root User

adduser ubuntu
usermod -aG sudo ubuntu

Add your SSH key to the new User

ssh-copy-id ubuntu@
ssh ubuntu@

Enabling Firewall

sudo ufw app list
sudo ufw status

Disable root login and password based login

sudo vim /etc/ssh/sshd_config

Uncomment and set:

PasswordAuthentication no
PermitRootLogin no

Restart ssh:

sudo systemctl restart ssh.service

Set Timezone

sudo timedatectl list-timezones
sudo timedatectl set-timezone Africa/Johannesburg
sudo apt install ntp

Install nginx

sudo apt install -y nginx

Install required OS packages for Python 3.10

sudo apt install -y build-essential checkinstall
sudo apt install -y libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev lzma

Get Python

cd /opt
sudo wget https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tgz
sudo tar xzf Python-3.10.2.tgz
cd Python-3.10.2

Compile:

sudo ./configure --enable-optimizations

Install alongside default system python3.8:

sudo make altinstall
python3.10 --version
Python 3.10.2

Install MySQL

sudo apt install -y mysql-server
sudo mysql_secure_installation

Python Mysqlclient

The mysqlclient python package requires

sudo apt install libmysqlclient-dev

Source