How to install Python in Ubuntu and Linux Mint

Guide to install latest Python in Ubuntu and derivatives

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:

python3 -V

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.

cd Downloads
tar -xvf Python-3.6.0.tgz

STEP 4: Now navigate into the extracted directory.

cd Python-3.6.0

STEP 5: You can now compile the source code. Enter the following command one by one.

./configure
make
make install

Python should now be installed on your computer.

Kiran Kumar
Hi there! I'm Kiran Kumar, founder of FOSSLinux.com. I'm an avid Linux lover and enjoy hands-on with new promising distros. Currently, I'm using Ubuntu as a daily driver and run several other distros such as Fedora, Solus, Manjaro, Debian, and some new ones on my test PC and virtual machines. I have a day job as an Engineer, and this website is one of my favorite past time activities, especially during Winter ;). When I'm not writing for FOSSLinux, I'm seen biking and hiking on scenic trails. I hope you enjoy using this website as much as I do writing for it. Feedback from readers is something that inspires me to do more and spread Linux love!. If you find a time, drop me an email or feedback from the 'Contact' page. Or simply leave a comment below if you found this article useful. Have a good day!

9 COMMENTS

  1. Hi Kiran,
    I’m not able to install python3.6 in linuxmint as i’m getting failures like E: Some index files failed to download. They have been ignored, or old ones used instead.I tried below steps also
    mint@mint ~ $ sudo cp /etc/apt/sources.list ~/
    mint@mint ~ $ sudo apt-get update
    but results were same,not able to install python3.6 on linuxmint 14.04.
    Could you please suggest to complete installation?
    Thanks in advance.

  2. Thanks Kiran,

    Python 3.7.4 is installed on Linuxmint 19 with your guidance.

    I got the following error after “make install”:
    ——ModuleNotFoundError: No module named ‘_ctypes’——

    Visited, https://github.com/pyenv/pyenv/issues/1183 and installation succeeded after running: sudo apt-get install libffi-dev

    Thanks a lot
    Nishant

  3. Thank you Kiran. Could not help thanking you. I have Linux Mint 19.3 installed on my Compaq laptop where Python 2.7 and 3.6 were already installed. I checked the Python.org website and found Python 3.8.1. Downloaded the latest and following your instructions (make, make install etc.) successfully updated Python 3.6 to 3.8.1. Only thing…’make’ ran ok but ‘make install’ needed sudo to run.
    Thanks a lot.

  4. Hi, when I got up to the end of the install it said it was successfully installed but is nowhere to be found. There is aslo a warning message:

    WARNING: The directory ‘/home/zac/.cache/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.

    Do you think anyone could help with this?

  5. The two versions of Python, 3.6 and 2.7 are required for Linux Mint 19.3 to function. Altering and/or replacing them is probably a very bad idea. Adding another version for use is not, and can run along side the other two. To use it you’ll simply address it by its version.

    The installation method provide here is incomplete and dangerous to your system if you try to ‘fix’ it by using what you think you know.

    The end install must be given the directive ‘make altinstall’ …
    Not ‘make install’.

    And the entire process aught to be sudo’d.

    Unpack your python tarbal under /usr/local/src
    and work from there.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,420FansLike
377FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

How to Create a Comprehensive Mail Server on Ubuntu

Postal is a free and open-source mail server used to send and receive emails. It comes loaded with tons of excellent features and functionalities, making it extremely popular among large organizations as well as in enterprise settings.

The 10 Best Linux Performance Monitoring Tools

Do you want to monitor the performance of your Linux system? Are you looking for some powerful performance monitoring tools to help you out? If you agree, it's your day as we have put together a detailed list of the ten best Linux performance monitoring tools.

How to Boot your Windows or Linux PC from a USB Drive

Sometime back, the process of installing an operating system required users to pop a bootable media disk into their DVD or CD drive and use it to boot the PC. But times have changed. Nowadays, the most common way of installing an OS is booting from a USB drive. The use of USB drives is further propelled by the current production of slim and lightweight laptops with no support for DVD/CD drives.

Python For Loop: Everything You Need to Know

Loops are one of the essential elements in any programming language, and Python is not an exception to it. Loops are used to repeat a statement or a block of statements multiple times. If there were no concept of loops in programming languages, we have to write each statement again and again for the number of times we want to execute it.

How to install LibreOffice on Fedora

If you are looking for a feature-rich and reliable Office Suite for your Fedora PC, then you have an excellent option at hand. LibreOffice, a free and opensource app, has stood the test of time and evolved into a beautiful alternative to Microsoft Office.

How to change Hostname on Ubuntu

Generally, a hostname is just an assigned name to a computer, laptop, or any other connected device to a network. You can say a hostname is a computer's nickname, and it is used to identify the machine over the network uniquely.

MUST READ

Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.
Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.

VIDEO: MX Linux 19 Features and Desktop Tour

MX Linux is a Linux distribution based on Debian stable and using core antiX components. The distributions MX Tools is very popular among users and combined with other several ready-to-use tools, it is great for users who prefer to tweak their distro to their liking. In this video, we will take you through the features tour showing casing MX Linux 19.

How to clone hard disk on Linux using Clonezilla

Disk cloning refers to the process of copying data from one disk to another, thus creating a one-to-one copy of the drive. Technically, this process is possible using the copy-and-paste method.

10 Best PDF Editors for Linux

In this article, we will take a look at 10 of the best PDF editors and tools out there in 2019 that are available for Linux platforms. The editors are going to be judged on the basis of their functionalities, portability, ease of installation, price, and convenience.

All about Ubuntu editions and which version should you use?

Ubuntu is one of the most popular Linux distributions developed and released by Canonical, and not without reason. It has very enriched repositories, with support for all the programs you could ever need.