Install Python on Linux

Python tutorial · PySpark.in

Install Python on Linux (Ubuntu / Debian / CentOS) — Step by Step

Python comes preinstalled on many Linux distributions, but often with an older version like Python 2.7 or Python 3.6.
To run modern programs, you should install the latest Python 3 version.

This step-by-step guide works for:

Step 1: Check if Python is already installed

Open Terminal and run:

python3 --version

If you see something like:

Python 3.10.12

Python is already installed.

If it says command not found, proceed to installation.

 Ubuntu / Debian / Linux Mint Installation

Step 2: Update your system

Step 3: Install Python 3

Step 4: Install pip (Python package manager)

Step 5: Verify installation

python3 --version

pip3 --version

You should see version information.

 CentOS / RHEL Installation

Step 2: Enable EPEL repository (required)

Step 3: Install Python 3

Step 4: Verify

 Fedora Installation

Fedora includes Python 3 by default. But you can install latest:

Verify:

Amazon Linux / AWS EC2 Installation

For Amazon Linux 2023:

For Amazon Linux 2:

Verify:

Step 6: Set Python 3 as the default (Optional)

Many Linux systems still use python → Python 2.

To set python → python3:

Now check:

Step 7: Run your first Python script

Create a file:

nano hello.py

Add:

print("Hello from Linux!")

Save → CTRL + O, then press Enter
Exit → CTRL + X

Run the script:

python3 hello.py

Output:

Hello from Linux!

Step 8: Install useful Python packages

pip3 install numpy pandas matplotlib

Note:

Step

Command

Update system

sudo apt update && sudo apt upgrade -y

Install Python

sudo apt install python3 -y

Install pip

sudo apt install python3-pip -y

Check version

python3 --version

Run script

python3 hello.py

More Python tutorials

All tutorials · Try the free PySpark compiler · Practice challenges