Install Python3 on Ubuntu

Updated: 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

Python3.7 needs more packages (ssl for example.), I will add this part later.

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]

Leave a comment