Install Python on Rocky Linux 8

Python is one of the most popular programming languages ​​in the world. With its simple and easy-to-learn syntax, Python is a great choice for both beginners and experienced developers.

Unlike other Linux distributions, Python is not installed by default on Rocky Linux 8.4

As you already know, there are two versions of Python being actively developed. While Python 2 is supported and active, Python 3 is considered the present and future of the Python language.

By default, RHEL/Rocky Linux 8 has no command pythonto avoid locking the user to a specific Python version. Instead, Rocky Linux gives users the option of installing, configuring, and running specific versions of Python. System tools like yumusing Python’s internal binaries and libraries.

This guide will walk you through installing Python 3 and Python 2 on Rocky Linux 8.

Install Python 3 on Rocky Linux 8

To start installing Python 3 on Rocky Linux 8, run the following command as root or user with privileges sudo in a terminal:

sudo dnf install python3 

To verify the installation, check the Python version by typing:

python3 --version 

At the time of writing this article, the latest version of Python 3 available in the Rocky Linux repositories is “3.6.x”:

Python 3.6.8 

The above command will also install pip on your Rocky Linux system.

To run Python, you need to type python3 explicitly and run pip type pip3.

You should always choose to install the python modules provided by the Rocky Linux distribution using yumor dnf, as they are supported and tested to work properly on Rocky Linux 8.

Python  Virtual Environmentsallows you to install Python modules in isolated locations for a specific project, rather than being installed globally. This way, you don’t have to worry about other Python projects.

Python 3 module package names begin with ” python3“. For example, to install the module paramiko , you would run:

sudo dnf install python3-paramiko 

Install Python 2 on Rocky Linux 8

Python 2 packages are also included in the default Rocky Linux 8 repository.

To install Python 2, enter the following command:

sudo dnf install python2 

Verify the installation by typing:

python2 --version 

The output will look like this:

Python 2.7.15 

To run Python 2, type python2, and to run pip type pip2.

Set the Default Python Version of Rocky Linux 8

If you have an app that relies on settings to find commands pythonin the system path, you have to create an unversioned python command and set the default version.

To set Python 3 as a python command to work system-wide, use the utility alternatives:

sudo alternatives --set python /usr/bin/python3 

For Python 2, type:

sudo alternatives --set python /usr/bin/python2 

Command alternativeswill create a symlink  pythonwhich points to the specified version of python.

Type python --versionin the terminal, and you will see the default Python version.

To change the default version, use one of the commands above. If you want to remove the unversioned python command, type:

sudo alternatives --auto python 


On Rocky Linux 8, Python is not installed by default.

To install Python 3, type dnf install python3and to install Python 2, type dnf install python2.

1 Trackback / Pingback

  1. Enable or Create a Service in Ubuntu 20.04 LTS - LinuxStoney

Leave a Reply

Your email address will not be published.