Install Python3 on Ubuntu

Created: October 27, 2019  |  1 minute read

Most of tutorials on the Internet about installing Python3.6 on Ubuntu are by using 3rd party PPA repositories. If for any reason, you cannot use them, hereunder a quick tutorial for installing it from the Python official source, you should in advance download the source to the Ubuntu.

Installing Python3.6 on Ubuntu 16.04

Disabling IPv6

IPv6 is enabled by default on Ubuntu 16.04, in some cases, your Ubuntu network connection might be very low due to IPv6. Use ip a | grep inet6 to check if IPv6 is enabled.

Ref: How to disable ipv6 address on ubuntu 18 04 bionic beaver linux

To disable IPv6 in a persist way, add following 2 lines in the file /etc/sysctl.conf and reload the sysctl by sudo sysctl --system or reboot the server:


Installing build packages

sudo apt install -y build-essential zlib1g-dev libssl-dev

without libssl-dev package, pip install will throw TLS/SSL error.

From this point of view, installing Python on Windows by Scoop is much more pleasant :)

Installing Python3.6 from official source

The latest Python3.6 version at the time of this writing is 3.6.9.

# You may download the Python source to a local shared location (S3 or Artifactory, etc.) if you need to deploy Python to many servers.
tar xzvf Python-3.6.9.tgz
cd Python-3.6.9
sudo ./configure --prefix=/opt/python3.6
sudo make
sudo make install
sudo ln -s /opt/python3.6/bin/python3.6 /usr/bin/python3.6

Python3.5 is preinstalled by default on Ubuntu 16.04, python3 -V gives Python 3.5.2, many system tools rely on it, please DO NOT bind python3 to any versions other than Python3.5, otherwise your system might have unexpected problems.

Using Python3.6 pip

python3.6 -m pip install [a python module]

Installing Python3.7 on Ubuntu 16.04

Just tested installing Python3.7.5 with the same procedure, all works.

Leave a comment