Skip to main content

Check existing Python

Most Linux distributions come with Python pre-installed. Let’s check:
python3 --version
If you see a recent Python 3 version, you’re ready! Most modern Linux distributions include Python 3.
Linux uses python3 to distinguish from the older Python 2. Some distributions let you use just python, but python3 always works.

Install or update Python

Choose your Linux distribution below:
  • Ubuntu/Debian
  • Fedora/RHEL/CentOS
  • Arch/Manjaro
  • openSUSE
  • Alpine

Update package lists

sudo apt update

Install Python and essential tools

sudo apt install python3 python3-pip python3-venv

Install development headers (for compiling packages)

sudo apt install python3-dev build-essential

For the latest Python version

If your distribution doesn’t have the latest Python:
# Add the deadsnakes PPA
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update

# Install specific version (example: 3.13)
sudo apt install python3.13 python3.13-venv python3.13-dev

Verify installation

Check that Python and pip are installed:
python3 --version
pip3 --version
You should see version numbers for both.

Test Python

  1. Start Python:
python3
  1. You’ll see the Python prompt:
Python 3.13.5 (main, Jul 29 2025, 12:03:01) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
  1. Try a simple command:
print("Hello from Linux!")
  1. Exit Python:
    • Type exit() or press Ctrl + D

Troubleshooting

For system packages: Always use sudo:
sudo apt install python3-pip
For pip packages: Install in user space:
pip3 install --user package-name
Best practice: Use virtual environments to avoid permission issues entirely.
Python isn’t installed. Install it using your package manager:
# Ubuntu/Debian
sudo apt update && sudo apt install python3

# Fedora
sudo dnf install python3

# Arch
sudo pacman -S python
pip isn’t installed. Fix it.
# Ubuntu/Debian
sudo apt install python3-pip

# Fedora
sudo dnf install python3-pip

# From Python
python3 -m ensurepip
Your distribution has an old Python. Options:

Option 1: Use deadsnakes PPA (Ubuntu/Debian):
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.13
Option 2: Compile from source:
# Install dependencies
sudo apt install build-essential zlib1g-dev libncurses5-dev \
  libgdbm-dev libnss3-dev libssl-dev libreadline-dev \
  libffi-dev libsqlite3-dev wget libbz2-dev

# Download and compile
wget https://www.python.org/ftp/python/3.13.5/Python-3.13.5.tgz
tar -xf Python-3.13.5.tgz
cd Python-3.13.5
./configure --enable-optimizations
make -j $(nproc)
sudo make altinstall
Option 3: Use pyenv for version management

Modern Linux prevents pip from installing system-wide. Solutions:

Use virtual environments (recommended):
python3 -m venv myenv
source myenv/bin/activate
pip install package-name
Install in user directory:
pip3 install --user package-name
Use pipx for applications:
sudo apt install pipx
pipx install application-name

Next steps

Great! Python is ready on your Linux system. Let’s set up your development environment.

Continue to VS Code introduction

Install and configure Visual Studio Code