This post will help install Python 3.6.10 on Ubuntu Desktop and Server. We are going to install Python 3.6.12, which is latest version of Python 3.6 with a few security fixes. Since, I going to download and install Python 3.6.12 from the source; it will take time and I also assume that you are comfortable with terminal and at the same time you should remove the preinstalled python 3.x from your system before you install python 3.6.x globally on your system.

You must have wget, make and tar installed your Ubuntu if you don’t have installed yet, you can install them with following commands.

sudo apt install wget make tar

Uninstall Preinstalled Python3.x

sudo apt remove python3 -y

Download Python 3.6.12

We are going to download Python 3.6.12 from the source and extract it

You can download python 3.6.12 .tar.xz file from https://www.python.org/downloads/release/python-3612/ or by clicking this direct download link.

Or you can user wget to download python source file

wget -P ~/Downloads https://www.python.org/ftp/python/3.6.12/Python-3.6.12.tar.xz

Extract Python 3.6.12

cd ~/Downloads
tar -xJf Python-3.6.12.tar.xz

Install Python 3.6.12 on Ubuntu

cd /Python-3.6.12
./configure
make
make test
sudo make altinstall
sudo apt update

Check Python version on Ubuntu

Let’s check installed python3 and pip3 version on Ubuntu. You can also check python3 and pip3 version with python3 –version and pip3 –version.

python3 -V 
pip3 -V 

Python 3.6.12 Alias

if you don’t like to type python3.6 on terminal every time you want to execute python code then this is going to be a time saver for you.

cd 
sudo nano .bashrc
alias py="python3"
alias pip="pip3"

To save the file, press CTRL+ O and CTRL+X and relaunch your terminal.

And now you can execute your python code with py and pip instead of python3.6, python3 and pip3.