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.
- RHEL 8 with Minimal Installation
- RHEL 8 with RedHat Subscription Enabled
- 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
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
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:
And to run Python 2, type:
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.
# 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.