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:
- Ubuntu
- Debian
- Linux Mint
- CentOS
- RHEL
- Fedora
- Amazon Linux
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
- sudo apt update && sudo apt upgrade -y
Step 3: Install Python 3
- sudo apt install python3 -y
Step 4: Install pip (Python package manager)
- sudo apt install python3-pip -y
Step 5: Verify installation
python3 --version
pip3 --version
You should see version information.
CentOS / RHEL Installation
Step 2: Enable EPEL repository (required)
- sudo yum install epel-release -y
Step 3: Install Python 3
- sudo yum install python3 -y
Step 4: Verify
- python3 --version
- pip3 --version
Fedora Installation
Fedora includes Python 3 by default. But you can install latest:
- sudo dnf install python3 -y
Verify:
- python3 --version
Amazon Linux / AWS EC2 Installation
For Amazon Linux 2023:
- sudo dnf install python3.11 -y
For Amazon Linux 2:
- sudo yum install python3 -y
Verify:
- python3 --version
Step 6: Set Python 3 as the default (Optional)
Many Linux systems still use python → Python 2.
To set python → python3:
- sudo ln -sf /usr/bin/python3 /usr/bin/python
Now check:
- python --version
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
- What is Python and Why is it used for Data Science and Data Engineering?
- How Does Python Work in the Backend? Internal Working of Python
- Top 30 Python Interview Questions for Data Science
- 3-Month Python Roadmap to Excel in Data Science and Machine Learning
- Python Data Types Explained – A Beginner’s Guide
- test
All tutorials · Try the free PySpark compiler · Practice challenges