How to Install Python 3 or Python 2 in RHEL 8

In RedHat Enterprise Linux 8, Python doesn’t come preinstalled. The main reason for this is that the RHEL 8 developers didn’t want to set a default Python version for users. Therefore as a RHEL user, you need to specify whether you want Python 3 or 2 by installing it. In addition, in RHEL, Python 3.6 is the default and fully supported version of Python. However, Python 2 remains available and you can install it.

In this short article, we will show how to install Python 3 and Python 2, and run them in parallel in RHEL 8 Linux distribution.

Requirements:

  1. RHEL 8 with Minimal Installation
  2. RHEL 8 with RedHat Subscription Enabled
  3. RHEL 8 with Static IP Address

Important: Most Linux distributions use Python for a number of libraries and tools as YUM package manager. Although Python is not installed in RHEL 8 by default, but yum still works even if you don’t install Python. This is because there is an internal Python interpreter called “Platform-Python” which is used by system tools. Platform-python can’t be used by applications but you can only employ it for writing system/administrative code.

How to Install Python 3 in RHEL 8

To install Python 3 on your system, use the DNF package manager as shown.

# dnf install python3
Install Python 3 in RHEL 8
Install Python 3 in RHEL 8

From the output of the command, Python3.6 is the default version which comes with PIP and Setuptools as dependencies.

How to Install Python 2 in RHEL 8

If you want to install Python 2 in parallel with Python 3, run the following command which will install Python 2.7 on your system.

# dnf install python2
Install Python 2.7 in RHEL 8
Install Python 2.7 in RHEL 8

How to Run Python in RHEL 8

After installing Python, you would expect that /usr/bin/python will run a certain version of Python. To dissociate itself from “Python2 or Python3: which version should be set as the default on Linux” debates, RedHat has not included a python command by default – what is referred to as the “unversioned command“.

To run Python 3, type:

# python3

And to run Python 2, type:

# python2

What if there are applications/programs on your system that expect a python command to exist, what do you need to do? It is simple, you use alternatives --config python command to easily make /usr/bin/python point to the correct location of the Python version you want to be set as the default version.

For example:

# alternatives --set python /usr/bin/python3
OR
# alternatives --set python /usr/bin/python2

That’s All! In this short article, we have shown how to install Python 3 and Python 2 on RHEL 8. You can ask questions or share your thoughts with us via the feedback form below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.