Python is one of the popular object-oriented programming languages used for developing many kinds of software. In today’s article, we will install Python on Ubuntu.
The biggest advantage of Python is its strong support for integration with other languages and tools, and the simplicity in which it can be learned in a few days.
It can be installed on most Operating systems including Linux, Windows, and Mac OSX. It is Free and Open Source Software (FOSS). This tutorial will help you in setting up and installing the latest version of Python on Ubuntu and its derivatives including Linux Mint and elementary OS.
Install Python on Ubuntu and Linux Mint
This tutorial is done on Ubuntu 16.04. It should work on Linux Mint 18.1 and above as well as elementary OS.
Ubuntu and Linux Mint come pre-installed with some version of Python. The only thing you need to verify is if it’s the latest version. To check the current version installed on your computer, launch ‘Terminal’ and type the following command:
You should see a lot of output in the terminal but look of Python version_number followed by the date. My Linux Mint PC gives says:
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
But as of when this article was written, the Python version available at the official website is Version 3.6.0. It’s always a good idea to have the latest version to get maximum features.
The easiest way of installing Python in Ubuntu and its derivatives is by using apt-get command. Of course, there is also a long way to manually download and install it. We shall discuss both the methods here.
METHOD 1: Using apt-get command
STEP 1: Launch Terminal.
STEP 2: Copy and paste the following command and hit enter to add J Fernyhough’s PPA.
sudo add-apt-repository ppa:jonathonf/python-3.6
STEP 3: Update the sources.
sudo apt-get update
STEP 4: Finally install Python 3.6 using apt-get command. It will download the installer package and install it. You will have to enter the root password when prompted.
sudo apt-get install python3.6
METHOD 2: Compile from Source Code
If you wish not to add any more PPAs into your computer, you can download the Python source code and compile it.
STEP 1: Before installing Python, it is recommended to install some dependencies. To do that, launch Terminal and copy-paste following commands in the terminal and hit enter.
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
STEP 2: Go to Download Python official webpage and download the latest version of Python. You can download the Gzipped source tarball.
STEP 3: Launch Terminal and navigate to the ‘Downloads’ folder or wherever you downloaded the Python .tgz package. Make sure to use the exact file name to extract after -xvf in the below command.
tar -xvf Python-3.6.0.tgz
STEP 4: Now navigate into the extracted directory.
STEP 5: You can now compile the source code. Enter the following command one by one.
Python should now be installed on your computer.