How to Install Python on Linux

  • Python

This tutorial is specific to those people whose Linux distribution didn’t come with Python installed or came with an earlier version of Python 2 like 2.7 or maybe an earlier version of Python 3.

1. Check if Python is already installed

$ python --version

or use

$ python3 --version

2. If your Linux distribution has Python 2 and doesn’t have Python 3 installed, install python with your package manager. The commands may vary for different flavors.

For Ubuntu :

$ sudo apt-get update
$ sudo apt-get install python3

For CentOS :

$ sudo yum update
$ sudo yum install yum-utils
$ sudo yum install python3

Note that if you want to install any specific version of Python, instead of running $ sudo apt-get install python3, use $ sudo apt-get install python3.8 or whichever version you want to install.