Home > Python > Install Python on Linux

Install Python on Linux

Python is the most popular programming language. Python is used for web development, Data Science, Machine Learning, Artificial intelligence, Operating Systems, Mobile application development, and video games. It supports multiple programming paradigms, including structured (particularly procedural), object-oriented and functional programming.

This article will guide you in installing Python through step by step instruction.

How to Install Python on Linux (Ubuntu)

$ sudo apt-get update
$ sudo apt-get install python3.8 python3-pip

How to Install Python on Linux (Linux Mint and Ubuntu 17 and below)

$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.8 python3-pip

How to Install Python on Linux (Using Source Code)

Step 1: Download the Source Code

Download the latest version of the python source code from the official download page.

Step 2: Prepare Your System

$ sudo apt-get update
$ sudo apt-get upgrade

For apt-based systems (like Debian, Ubuntu, and Mint)

$ sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
       libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
       libncurses5-dev libncursesw5-dev xz-utils tk-dev

For yum-based systems (like CentOS)

$ sudo yum -y groupinstall "Development Tools"
$ sudo yum -y install gcc openssl-devel bzip2-devel libffi-devel

Step 3: Build Python

$ tar -xvf Python-3.8.4.tgz
$ cd Python-3.8.4
$ ./configure --enable-optimizations --with-ensurepip=install
$ make -j 8
$ sudo make altinstall

Wait for the process to complete.

Verify the installation

$ python3 --version

OR 

$ python --version

If the output is the version you downloaded for installation, Happy Coding!

More Tutorials on Python –

Install Python on macOS

Install pip, virtualenv environment and activate the virtualenv in Linux