> ## Documentation Index
> Fetch the complete documentation index at: https://fastapi2day.codewithsiva.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Installing Python on Linux: apt, dnf, pacman and More

> Step-by-step guide to installing Python on Ubuntu, Debian, Fedora, Arch, and other Linux distributions using your system's native package manager.

Most modern Linux distributions ship with Python 3 pre-installed, which makes getting started particularly smooth on Linux. Even if your system Python is present, it is good practice to verify the version, ensure `pip` and `venv` are available, and understand how to install a newer release if your distribution packages an older one. This guide covers the most popular distributions and their package managers.

## Check what is already installed

Open a terminal and run:

```bash theme={null}
python3 --version
```

If you see Python 3.10 or later, you are in good shape for this course. Also check that `pip` is available:

```bash theme={null}
pip3 --version
```

<Note>
  Linux uses `python3` to distinguish from the legacy Python 2 interpreter, which is still present on some older distributions. Always use `python3` explicitly unless you have configured a `python` alias or symlink yourself.
</Note>

If Python is missing, outdated, or `pip` is not found, the steps below will get you sorted.

## Install or update Python

<Tabs>
  <Tab title="Ubuntu / Debian">
    <Steps>
      <Step title="Update your package lists">
        ```bash theme={null}
        sudo apt update
        ```
      </Step>

      <Step title="Install Python, pip, and venv">
        ```bash theme={null}
        sudo apt install python3 python3-pip python3-venv
        ```

        `python3-venv` gives you the `venv` module for creating isolated project environments — you will use this throughout the course.
      </Step>

      <Step title="Install development headers (optional but recommended)">
        Some Python packages compile native extensions during installation. The development headers are needed for that:

        ```bash theme={null}
        sudo apt install python3-dev build-essential
        ```
      </Step>

      <Step title="Get the latest Python via the deadsnakes PPA (optional)">
        If your distribution ships an older Python 3 version and you want the latest release:

        ```bash theme={null}
        sudo add-apt-repository ppa:deadsnakes/ppa
        sudo apt update
        sudo apt install python3.13 python3.13-venv python3.13-dev
        ```

        <Tip>
          The [deadsnakes PPA](https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa) is maintained by the Python community and provides up-to-date Python packages for Ubuntu. It is widely trusted and used.
        </Tip>
      </Step>
    </Steps>
  </Tab>

  <Tab title="Fedora / RHEL / CentOS">
    <Steps>
      <Step title="Install Python, pip, and development headers">
        ```bash theme={null}
        sudo dnf install python3 python3-pip python3-devel
        ```
      </Step>

      <Step title="Install compilation tools">
        ```bash theme={null}
        sudo dnf groupinstall "Development Tools"
        ```
      </Step>

      <Step title="Install a newer Python version (optional)">
        Check which versions are available:

        ```bash theme={null}
        dnf search python3
        ```

        Install a specific version:

        ```bash theme={null}
        sudo dnf install python3.13
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="Arch / Manjaro">
    <Steps>
      <Step title="Install Python and pip">
        Python is usually pre-installed on Arch. If it isn't:

        ```bash theme={null}
        sudo pacman -S python python-pip
        ```
      </Step>

      <Step title="Install base development tools">
        ```bash theme={null}
        sudo pacman -S base-devel
        ```
      </Step>

      <Step title="Install a specific version from the AUR (optional)">
        ```bash theme={null}
        yay -S python313
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="openSUSE">
    <Steps>
      <Step title="Install Python, pip, and headers">
        ```bash theme={null}
        sudo zypper install python3 python3-pip python3-devel
        ```
      </Step>

      <Step title="Install the development pattern">
        ```bash theme={null}
        sudo zypper install -t pattern devel_basis
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="Alpine">
    <Steps>
      <Step title="Install Python and pip">
        ```bash theme={null}
        apk add python3 py3-pip python3-dev
        ```
      </Step>

      <Step title="Install build tools">
        ```bash theme={null}
        apk add build-base
        ```
      </Step>
    </Steps>
  </Tab>
</Tabs>

## Verify your installation

After installation, confirm both Python and pip are accessible:

```bash theme={null}
python3 --version
pip3 --version
```

Expected output (version numbers will vary):

```text theme={null}
Python 3.13.5
pip 24.0 from /usr/lib/python3/dist-packages/pip (python 3.13)
```

## Test the Python interpreter

Launch the Python REPL to confirm everything is working end-to-end:

```bash theme={null}
python3
```

You will see the `>>>` prompt:

```text theme={null}
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.
>>>
```

Try a quick command:

```python theme={null}
print("Hello from Python on Linux!")
```

Exit with `exit()` or **Ctrl + D**.

## Troubleshooting

<AccordionGroup>
  <Accordion title="'python3' command not found" icon="circle-exclamation">
    Python is not installed (or not in your PATH). Install it using your package manager:

    ```bash theme={null}
    # Ubuntu / Debian
    sudo apt update && sudo apt install python3

    # Fedora
    sudo dnf install python3

    # Arch
    sudo pacman -S python
    ```

    After installation, open a new terminal and try `python3 --version` again.
  </Accordion>

  <Accordion title="'pip3' command not found" icon="box">
    pip is not installed. Fix it with your package manager or the Python built-in bootstrap:

    ```bash theme={null}
    # Ubuntu / Debian
    sudo apt install python3-pip

    # Fedora
    sudo dnf install python3-pip

    # Arch
    sudo pacman -S python-pip

    # Any distro — use Python's built-in ensurepip
    python3 -m ensurepip --upgrade
    ```
  </Accordion>

  <Accordion title="Permission denied when installing packages" icon="lock">
    On Linux, you should never install pip packages into the system Python with `sudo pip3 install` — it can conflict with system packages.

    **Preferred solution — use a virtual environment:**

    ```bash theme={null}
    python3 -m venv myenv
    source myenv/bin/activate
    pip install package-name
    ```

    Inside the virtual environment, `pip install` works without `sudo` or permission issues.

    **Alternative — install in your user directory:**

    ```bash theme={null}
    pip3 install --user package-name
    ```
  </Accordion>

  <Accordion title="externally-managed-environment error (pip refuses to install)" icon="ban">
    Modern Ubuntu (23.04+) and other distributions enforce PEP 668, which prevents pip from installing packages into the system Python environment. This is intentional — it protects system tools.

    **Use a virtual environment (recommended):**

    ```bash theme={null}
    python3 -m venv myenv
    source myenv/bin/activate
    pip install package-name
    ```

    **Install in user directory:**

    ```bash theme={null}
    pip3 install --user package-name
    ```

    **Use pipx for standalone tools:**

    ```bash theme={null}
    sudo apt install pipx
    pipx install tool-name
    ```
  </Accordion>

  <Accordion title="Python version is too old" icon="clock">
    If your distribution ships an outdated Python 3 (e.g., 3.8 on older Ubuntu), you have several options:

    **Option 1 — deadsnakes PPA (Ubuntu/Debian):**

    ```bash theme={null}
    sudo add-apt-repository ppa:deadsnakes/ppa
    sudo apt update
    sudo apt install python3.13
    ```

    **Option 2 — compile from source:**

    ```bash theme={null}
    # Install build 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 build Python 3.13
    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
    ```

    <Note>
      Use `make altinstall` (not `make install`) to avoid replacing the system `python3` symlink.
    </Note>

    **Option 3 — pyenv:** A dedicated version manager that installs any Python version in your home directory without touching system files. Install it from [github.com/pyenv/pyenv](https://github.com/pyenv/pyenv).
  </Accordion>
</AccordionGroup>

## Next steps

<Card title="Continue to VS Code Introduction" icon="arrow-right" href="/getting-started/vscode-introduction">
  Install and configure Visual Studio Code as your Python editor.
</Card>
