How to Install Python on Ubuntu Without Hassle

How to Install Python on Ubuntu Without Hassle

Python is a widely-used programming language for creating automation scripts and various other applications. While Python 3 is the latest version, Python 2 is nearly deprecated. I frequently use Python for software development, particularly for creating APIs, scripting, and web scraping, which is why I prioritize setting up Python in my development environment.

Is Python already installed on your linux machine?

I have experimented with Ubuntu 20.04 and 22.04 in WSL on my Windows machine. From this experience, I know that nearly every Ubuntu release comes with a specific version of Python automatically installed, as the default Ubuntu (Linux Distros) software heavily depends on Python.

Just to be sure python is installed on your machine, go to applications and search for “Terminal” or press “Ctrl+Alt+T” once the terminal opens, enter the command below

python3

This should show a python console in the terminal with the python version displayed on the first line; you can exit the console by pressing “Ctrl + D”, or type “exit()” and hit enter button on the keyboard.

If the command throws an error saying "bash: python3: command not found," Python is not installed.

Install Python

Most cases the version of python that comes out of the box with Ubuntu distro is not the latest version. For example, my Ubuntu installation came with Python3.10 preinstalled, while there is Python3.13 stable release from the official python website.

Why use lower version pre-installed? As earlies stated, Ubuntu use a lot of Python under the hood, so a stable version is used a base till next version of ubuntu is released in order to avoid breaking dependencies.

You can install python on your Ubuntu using the following methods:

  1. From the default ubuntu repository using APT

  2. From the official python website, download the source code; I haven’t tried it!

  3. From a third-party repository for ubuntu known as Deadsnakes PPA, with newer releases than the default ubuntu repository.

Using APT:

sudo apt update
sudo apt install python3

Using PPA(Personal Package Archive):

sudo apt update
sudo apt install software-properties-common

The software-properties-common package gives better control over your package manager by letting you add PPA repositories.

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update

Specify the version you want to install, python3.8, python3.11, python3.12, python3.13,python3.14. In my own case, I installed the 3.12.

sudo apt install python3.12

Congratulations you have succeeded in installing a newer version of python aside the default that comes with your ubuntu installation.