How to Install Python 3.6 on Ubuntu 16.04

The good thing about Ubuntu 16.04, as far as the Python programming environment is concerned, is that it comes with pre-installed Python3 support. For many years, the Python community has lived in the 2.7 vs. 3.0 divide, with many refusing the migrate. Eventually, however, the community at large came to appreciate the design decisions behind version 3 and started to adopt it. As a result, Ubuntu 16.04 comes with both versions installed.


That said, Python 3.6 is another game-changer and is, unfortunately, not bundled in the official repositories of Ubuntu 16.04. In fact, even as the next LTS release (18.04) is due in short time, the repositories have not been updated to 3.6. The best you can find on Ubuntu 16.04 is 3.5.2. Does that mean you need to wait till the next LTS before you can get your hands on Python 3.6? Absolutely not!


But before we look at how to install Python 3.6 on Ubuntu 16.04, let’s look at why programmers think Python 3.6 is a gift of the gods. Some of the neat features in Python 3.6 are:


Cool new shortcuts: Python 3.6 borrows some really cool syntactic features from the likes of the Ruby language. String interpolation and nicer numbers (1_000_000 for a million, for example), have made an appearance.

Co-routines: The single biggest addition to the Python interpreter in its 3.6 version is support for co-routines. This is another area where Python was heavily influenced by the developments in .NET and Java ecosystems, and accepted the keywords ‘async’ and ‘await’ as it is.

Type hinting: The software development wisdom seems to have come around full-circle; compiled languages and strong types are now recognized for their sheer usefulness. As a result, Python added support for type annotations and for primitives.

Asynchronous everything: Support for asynchronous generators and comprehensions has been added.

Faster, with lesser memory: The dictionary data type has been overhauled in Python 3.6, and boasts of better speed and around 25% less memory usage.


The list goes on, but for Python enthusiasts out there, this is more than enough reason to run for their copy of Python 3.6.


Installing Python 3.6 on Ubuntu 16.04 Using apt


If you prefer not to build software from source (which is something we don’t recommend at all – unless you’re sure of yourself), it’s better to let the package management system take care of it.


The default channels in Ubuntu contain Python 3.5, but they can be easily upgraded. Make sure you are logged in as root user (if not, add ‘sudo’ before each of these commands), and then issue these commands:


# add-apt-repository ppa:jonathonf/python-3.6


(you’ll need to hit Enter to accept this PPA)


# apt-get update


# apt-get install python3.6


This adds the PPA maintained by a contributor called J. Fernyhough, and contains the 3.6 version of the interpreter.


And that’s it! Now you can access Python 3.6 by typing ‘python3.6’ on the terminal. Note that the other versions still live on in your system, and can be invoked using the corresponding number (for example, ‘python2.7’).