Python can be installed on Linux using package managers, version managers, or by building it from source. Most Linux distributions already include Python, but installing the latest version ensures access to new features, performance improvements, and security updates.
Python Versions
Python has two major versions:
Python 2
- Legacy version
- No longer maintained
- Not recommended for new projects
Python 3
- Actively maintained
- Receives security updates
- Recommended for modern development
Note: Always use Python 3 for new projects.
Pre-Installation Checklist
Before installing Python, ensure you have:
- Sudo or root privileges
- Terminal access
- An active internet connection
- At least 200 MB of available disk space
- Basic familiarity with terminal commands
Python Installation check
Check Python 3:
python3 --version
Check Python 2:
python --version
If Python is installed, the terminal displays its version number like following example:
Python 3.13.1
Install Python Using Package Managers
Package managers provide the simplest and recommended way to install Python.
Ubuntu and Debian (APT)
Update Package Repository:
sudo apt update
Upgrade Installed Packages:
sudo apt upgrade
Install Python
sudo apt install python3
Install pip
sudo apt install python3-pip
Install Development Tools
sudo apt install python3-dev python3-venv build-essential
Fedora (DNF)
Update Package Repository:
sudo dnf update
Install Python
sudo dnf install python3
Install pip
sudo dnf install python3-pip
Install Development Tools
sudo dnf groupinstall "Development Tools"
Arch Linux (Pacman)
Update System
sudo pacman -Syu
Install Python
sudo pacman -S python
Install pip
sudo pacman -S python-pip
CentOS and RHEL (YUM)
Update System
sudo yum update
Enable EPEL Repository
sudo yum install epel-release
Install Python
sudo yum install python3
openSUSE (Zypper)
Refresh Repositories
sudo zypper refresh
Install Python
sudo zypper install python3
Install Development Files
sudo zypper install python3-devel
Install Python Using Version Managers
Version managers are useful when working with multiple Python versions. Popular options include:
- Pyenv
- asdf
Use version managers when:
- Working on multiple projects
- Testing different Python versions
- Managing project-specific environments
Note: Keep only Pyenv and remove asdf to reduce complexity.
Install Python from Source Code
Building from source provides full control over the installation.
Install Dependencies
sudo apt install build-essential libssl-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm \
libffi-dev zlib1g-dev
Download Python:
wget https://www.python.org/ftp/python/X.Y.Z/Python-X.Y.Z.tgz
Extract Files:
tar -xvf Python-X.Y.Z.tgz
cd Python-X.Y.Z
Configure:
./configure --enable-optimizations
Build and Install:
make -j $(nproc)
sudo make altinstall
Install Python Using Deadsnakes PPA (Ubuntu)
Deadsnakes provides newer Python versions that may not be available in Ubuntu repositories.
Install Required Package:
sudo apt install software-properties-common
Add Repository:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
Install Python:
sudo apt install python3.13
Python Installation Commands by Distribution
| Distribution | Package Manager | Install Command |
|---|---|---|
| Ubuntu/Debian | APT | sudo apt install python3 |
| Fedora | DNF | sudo dnf install python3 |
| Arch Linux | Pacman | sudo pacman -S python |
| CentOS/RHEL | YUM | sudo yum install python3 |
| openSUSE | Zypper | sudo zypper install python3 |