Skip to main content

Complete Guide to Installing Python on Linux (2026)

Hello and welcome to this comprehensive guide dedicated to installing Python on Linux. If you are a developer, a data scientist, or just an enthusiast taking your first steps in the world of programming, this guide is for you.

Python is one of the most beloved and versatile languages in the world, but managing it on an operating system as powerful as Linux can sometimes be confusing, especially when dealing with different versions.

In this article we will see not only how to install Python on Linux, but also how to manage multiple versions at the same time without creating conflicts. We'll start from the basics all the way to more advanced techniques such as compiling from source.

Is Python Really Necessary to Install on Linux?

This is a very good question. Most Linux distributions (such as Ubuntu, Fedora, and Debian) arrive with Python already pre-installed. This is because many internal system tools use Python to work properly.

However, the pre-installed version may not be the latest available or the one you need for your project. Running a check is the critical first step.

Step 1: Verify the Python Version Already Installed

Open a terminal (you can look it up in applications or use the shortcut Ctrl+Alt+T on many distributions) and run these commands:

python3 --version

You may receive an output such as Python 3.10.12. If the command returns an error, it means Python 3 is not installed or is not in the system PATH.

Step 2: Install Python with the Package Manager (Recommended Method)

The easiest and safest way to install software on Linux is to use your distribution's package manager. This tool automatically handles dependencies and updates.

On Debian/Ubuntu distributions

For Ubuntu and other Debian-based distros, you use apt.

  1. Update package list:

    sudo apt update
  2. Install Python 3:

    sudo apt install python3

On RHEL/Fedora/CentOS distributions

For Fedora, CentOS, and other Red Hat-based distros, you use dnf (or yum in older versions).

  1. Install Python 3 with dnf:

    sudo dnf install python3

For a more detailed step-by-step guide, you can check out the GeeksforGeeks on how to install Python on Linux.

How to Update Python to the Latest Version

Using the package manager is also the best way to update Python. When you upgrade your system, Python will also be ported to the most recent version officially supported by your distribution.https://www.microsoft.com/en-gb/software-download/windows10ISO

On Ubuntu/Debian, run:

sudo apt update
sudo apt upgrade

However, Linux distributions tend to prioritize stability, so you may not find the very latest version of Python (e.g., 3.13) in the official repositories right away. If you need just the latest release, the next section is for you.

Managing Multiple Versions of Python with pyenv (Advanced)

What if one project requires Python 3.9 and another Python 3.11? Changing the system version is risky. The solution is called pyenv.

Why use pyenv?

pyenv is a tool that allows you to:

  • Install different versions of Python on the same machine.
  • Set a specific version globally, locally (for a single folder) or for the current session.
  • Switch from one version to another with a simple command, without using sudo.

Installing pyenv

Installing pyenv is usually done via an automated script. For the most up-to-date and detailed instructions, always refer to the official pyenv repository on GitHub.

Once installed, you can install a new version of Python with a simple command such as:

pyenv install 3.11.4

And then activate it for your project folder:

pyenv local 3.11.4

Blocked in Configuration? Optimize Your Linux Environment Today!

Managing packages, versions, and dependencies on Linux can become a full-time job. If you prefer to focus on development instead of system maintenance, our Linux Consulting service is the solution.

Our experts can configure, optimize and secure your development environment, ensuring you always have the right tools at the right time.

Contact us for a Free Consultation and Find Out How We Can Help You!


Creating a Python Virtual Environment in Linux

Installing different versions of Python is only half the work. For each project, it is a good practice to create a virtual environment. A virtual environment is an isolated folder that contains a specific version of Python and its libraries, independent of the rest of the system.

The venv module is already included in Python 3. To create an environment:

  1. Go to your project folder:

    mkdir my-project
    cd my-project
  2. Create the virtual environment (e.g. call it .venv):

    python3 -m venv .venv
  3. Activate the environment:

    source .venv/bin/activate

Your terminal prompt will change, indicating that you are now inside the virtual environment. To exit, you will simply type deactivate. For a more in-depth look, The official docs offers an excellent guide on virtual environments.

FAQ: Frequently Asked Questions about Installing Python

How do you install pip on Linux?

pip is the package manager for Python. It is usually installed along with Python. If for some reason it is missing, you can install it like this:

sudo apt install python3-pip # On Debian/Ubuntu
sudo dnf install python3-pip # On Fedora/CentOS

Can I set Python 3 as the default?

We recommend changing the symlink of /usr/bin/python to make it point to python3. Many system scripts expect python to be Python 2. Altering this behavior can cause unpredictable problems. The best solution is to use pyenv to handle the default user-level version or use the alias python3 directly.

When should I compile Python from source?

Compiling Python from source is a task for experienced users, needed only in specific cases:

  • You need a version of Python not yet available via pyenv or package manager.
  • You need to enable specific build flags to optimize performance.
  • You are working on a non-standard Linux distribution.

The process requires you to download source code from the Official Python website and follow the compilation instructions.

Do you need Help with Configuring Your Linux Environment?

We hope this guide was helpful to you! Configuring a clean and functional development environment is the first step to a successful project. If you have encountered difficulties or want a professional setup for your team, our Linux Consulting service is at your disposal. We will help you optimize your workflow, from package management to containerization.

Talk to one of our experts and take your Linux environment to the next level!

Add new comment

Comment

  • Allowed HTML tags: <br> <p> <code class="language-*"> <pre>
  • Lines and paragraphs break automatically.
  • Only images hosted on this site may be used in <img> tags.