How to install Python in Ubuntu and Linux Mint

In this tutorial, we shall take a closer look at various ways of installing Python on your Ubuntu and derivatives, including Linux Mint, Pop!_OS, and more.

Python is one of the most popular programming languages used for developing many kinds of software. Python is a popular choice for both beginners and expert programmers. Due to its easy to learn syntax and powerful libraries, it is loved and adopted by millions of programmers all over the world.

Python can do any task, including Web Development, Data Science, Artificial Intelligence, Automation, or any other General Programming task. Python can be used to build applications for any platform, including Linux, Windows, or Mac. Now Python has also supported building Android applications due to the Kivy library. In today’s article, we will see how to install Python on Linux.

The most significant advantage of Python is its strong support for integration with other languages and tools. People also love the simplicity in which it can be learned in a few days compared to other languages, which takes more time to be learned. Python has many different libraries; we can store data in Python using the SQLite databases in Python, which is a great way to store our application data in Python.

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. If you love Linux, you may also look at the article on using Linux shell commands in Python.

Installing Python on Ubuntu and Linux Mint

This tutorial is done on Ubuntu 16.04. It should work on all Ubuntu derivatives, including Linux Mint, Pop!_OS, elementary OS, and more.

Ubuntu, Linux Mint, and many other Linux OS 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 pay attention to the Python version_number, followed by the date.

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 full features.

The easiest way of installing Python in Ubuntu and its derivatives is by using the apt-get command. Of course, there is also a long way to download and install it manually. We shall discuss both the methods here.

METHOD 1: Using the 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 the 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 successfully. After installing Python, you may use one of the best python IDE so you can write code quickly and fast..

Conclusion

This tutorial explains everything about how to install and update Python on a Linux system. You may also want to see our step by step guide on installing anaconda in Python. Installing anaconda will let you efficiently manage python packages and maintain a different version of Python by creating virtual environments.

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,241FansLike
389FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

MUST READ

The Ubuntu Cinnamon Remix brings together Linux Mint's Cinnamon desktop with the Ubuntu Core. While some users are welcoming the new flavor of Ubuntu with open arms, others are scratching their heads, wondering where it fits in.
The wait is finally over (almost) for all you Ubuntu fans out there. The latest version of Ubuntu, 20.10 codenamed "Groovy Gorilla," is currently available in the beta version. I have tested out the distro myself, and it is stable enough to take out for a spin.

Removing the Virus from a Windows PC with a Ubuntu Live USB drive

In this tutorial, we are going to show you how to clean your Windows machine from infected viruses using an Ubuntu live USB or CD and the ClamAV antivirus. The ClamAV is a free, open-source antivirus that can be used on Ubuntu.

Guide to watching Disney+ on Linux

Disney Plus or Disney+ is an on-demand entertainment streaming service in which you should see the content produced by Disney Studios, Star Wars, Marvel, Pixar, and National Geographic. The service was launched on the 12th of November 2019.

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.

How to dual-boot Ubuntu and Fedora on your PC

Every Linux distribution has its capabilities and preferences as per the user requirements. That brings forth the need to run different distros on one laptop. For example, a CyberSecurity enthusiast might prefer to use Ubuntu for development and Kali Linux for penetration testing.