How to install Python on Linux?

First published: | Last updated:

Learn how to build, compile, and install the Python interpreter on the Linux operating system.


What is Python?

Python is a versatile, interpreted, object-oriented, high-level programming language with dynamic semantics. It offers high-level built-in data structures and utilizes dynamic typing and dynamic binding, making it extremely appealing for quick application development. Additionally, it is often used as a scripting or glue language to connect different existing components.

Install Python

To install Python from its source code, we will need to build, compile it and then proceed with the installation process. Once Python is successfully installed, it is crucial to verify the installation by checking its version. For further information and detailed instructions, please refer to the official Python documentation.

Linux (RPM)

You can use the following commands to install Python in RPM-based Linux operating systems such as CentOS LinuxRed Hat LinuxFedora LinuxAmazon LinuxAlma LinuxRocky Linux, etc., or any other similar equivalents.

# Install Python.
$ sudo yum install python3.12

# Set Python 3.12 as default interpreter and Python 3.9 as fallback interpreter.
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 2

# List Python versions.
$ sudo update-alternatives --list python

# Check Python version.
$ python --version

Linux (Debian)

You can use the following commands to install Python in Debian-based Linux operating systems such as Ubuntu LinuxMint LinuxKali LinuxKubuntu Linux, etc., or any other similar equivalents.

# Install Python.
$ sudo apt install python3.12

# Set Python 3.12 as default interpreter.
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1

# List Python versions.
$ sudo update-alternatives --list python

# Check Python version.
$ python --version
Logo of SloopStash organization.

What's next? Let's connect to meet your IT demands.

Products Toolkits Solutions Training


Experience business-class software products, open source toolkits, technology solutions, and training, designed with cybersecurity, automation, and AI in mind.