Python May Already be Installed

If you’re using Linux, odds are that python is already installed. If you’re using Ubuntu desktop edition, for example, you will already have python3.

However, if you have a different distribution, or if you customized your install, you may not have python and may need to add it.
Not all Linux installs have a desktop included, so we’ll use a terminal in this guide (using Ubuntu version 20 in the screenshots).
So, step 1 is to open your terminal, if you haven’t already. You can do this by pressing Ctrl-Alt-T

In the terminal, type python3 –version. If this returns a version number, then you’re good to go, python is installed.

Checking the python version in linux

Installing Python on Linux

We’ll use the apt-get Linux tool to download and install python.
The first step is to check that apt-get itself is up to date. The command below uses Sudo which enables extra privileges in Linux and is required for some programs to run. This will ask for your password to continue.

sudo apt-get update

apt-get will then connect to the internet and update itself.

Updating apt-get in linux

Next to install the latest version of python:

sudo apt-get install python

This will ask you to confirm tha that you’re happy to proceed. Press Y to continue.

Using apt-get to install python

Multiple Python Versions

It’s possible to have multiple versions of python installed in Linux at one time. In fact, you probably already have python 2 and python 3.

user@ubuntu:~$ python --version
Python 2.7.18
user@ubuntu:~$ python3 --version
Python 3.8.10

Python 2 is a bit old now and is included so you can use old pythons scripts. I recommend that you use python 3 for any new projects.

You can also have multiple versions within a major version. For example, python 3.8 and python 3.10.

As this is a beginner’s guide, we won’t get into that right now.

Leave a Reply