Help Docs Server Administration Linux Server Administration Installing Python 3

Installing Python 3

Python 3 on Linux: Install via apt/dnf. *Crucial: Don't break system Python!* Use pip with virtual environments for safe package mgmt.

Python is a high-level, interpreted language known for its readability and versatility, supporting multiple programming paradigms such as object-oriented, procedural, and functional programming. On Linux, Python is commonly preinstalled or easily available via package managers, making it accessible for a wide range of tasks including system scripting, automation, software development, data analysis, and web applications. Many Linux system tools and utilities are written in Python, and it is widely used by both beginners and experienced developers due to its simple syntax and extensive standard library.

Installing Python 3

Before you install python 3 make sure you are not installing the same version that the Operating system already has on it by default.  Doing so will cause the default python libraries to not be recognized and this will stop yum from working until the newly added library file is found and removed.

Installing Python on popular Linux distributions can be done in several ways, each with its own advantages. Here are the most common methods:

This is generally the easiest and most recommended method as it leverages the distribution’s official repositories, ensuring compatibility and easy updates.

Ubuntu/Debian-based distributions (e.g., Ubuntu, Linux Mint, Pop!_OS):

  • Update package lists:
sudo apt update
  • Install Python 3 (usually already installed, but good to ensure):
sudo apt install python3
  • Install pip (Python’s package installer):
sudo apt install python3-pip

Fedora/RHEL-based distributions (e.g., Fedora, CentOS, Rocky Linux, AlmaLinux):

  • Update package lists:
sudo dnf update
  • Install Python 3 (usually already installed):
sudo dnf install python3
  • Install pip (usually included with python3): Pip is generally installed alongside Python 3. If not, you might find a python3-pip package, or it may be implicitly handled. Fedora is generally good about providing current Python versions.

Important considerations:

  • System Python: Most Linux distributions come with Python pre-installed because many system utilities rely on it. It’s generally best not to modify or remove this system Python to avoid breaking your operating system.
  • pip and Virtual Environments: Always use pip (Python’s package installer) within a virtual environment. Virtual environments (venv, conda, pipenv, poetry) isolate project dependencies, preventing conflicts between different projects and keeping your global Python installation clean.
  • Permissions: You’ll often need sudo for system-wide installations (using package managers or make install). When using version managers or conda, installations are typically done in your user’s home directory and don’t require sudo.
Was this article helpful?