fbpx

How to Install Python on Linux

Avatar for Noman Mohammad

By Noman Mohammad

Published on:

How to Install Python on Linux
Your rating ?

Python is a must-have tool for coding, automation, and tech projects. Installing it on Linux is quick and easy. Follow this simple guide to get Python running on your system in minutes.


Check if Python is Already Installed

Most Linux systems come with Python pre-installed. Let’s check!
Open your terminal and type:

python3 --version


If you see a version number (like Python 3.10.6), Python is ready! If not, follow the steps below.


Install Python Using Your Package Manager

Linux uses “package managers” to install software. Pick your system type below.

For Debian/Ubuntu (APT):

  1. Update your system:
sudo apt update
  1. Install Python:
sudo apt install python3  

For Fedora/CentOS (DNF):

  1. Update your system:
sudo dnf update  
  1. Install Python:
sudo dnf install python3  


Wait for the installation to finish. Done!


Install the Latest Python from Source

Need the newest Python version? Build it from source.

  1. Install tools needed to compile Python:
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev  


(For Fedora, use sudo dnf groupinstall "Development Tools")

  1. Download Python’s source code:
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz  
  1. Extract the file:
tar -xvf Python-3.12.0.tgz  
  1. Build and install Python:
cd Python-3.12.0  
./configure --enable-optimizations  
make -j 8  
sudo make install  


This takes 5-10 minutes. Be patient!


Verify Python is Working

Check if Python installed correctly. Type in the terminal:

python3 --version  


You should see the version number.

Test Python with a simple program:

python3 -c 'print("Hello, Linux!")'  


If it shows Hello, Linux!, you’re all set!


Final Thoughts

You’ve installed Python on Linux! Start coding, build apps, or automate tasks.

Need help? Comment below! Loved this guide? Share it with friends.

Leave a Comment