(Last Updated On: December 1, 2018)

Red Hat Enterprise Linux 8 public beta was announced on November 14, 2018. RHEL 8 has been built with development agility and production stability in mind. The default version of Python in RHEL 8 is Python 3.6. But Python 2 remains available in RHEL 8.

If for any reason Python 3.6 is missing in your Red Hat Enterprise Linux 8 installation, you’ll need to install it manually.

Install Python 3 on RHEL 8

Python 3.6 can be installed on RHEL 8 by running the command below on your terminal.

sudo yum install python3

Python 3 add-on packages generally have the python3 prefix in their names. For example, the dns module can be installed using:

$ sudo yum -y install python3-dns
Updating Subscription Management repositories.
Updating Subscription Management repositories.
Last metadata expiration check: 0:05:57 ago on Fri 30 Nov 2018 03:57:18 AM EST.
Dependencies resolved.
=======================================================================================================================================================
 Package                        Arch                      Version                          Repository                                             Size
=======================================================================================================================================================
Installing:
 python3-dns                    noarch                    1.15.0-8.el8                     rhel-8-for-x86_64-baseos-beta-rpms                    253 k

Transaction Summary
=======================================================================================================================================================
Install  1 Package

Total download size: 253 k
Installed size: 1.0 M
Downloading Packages:
python3-dns-1.15.0-8.el8.noarch.rpm                                                                                     50 kB/s | 253 kB     00:05    
-------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                   50 kB/s | 253 kB     00:05     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                               1/1 
Installed: python3-dns-1.15.0-8.el8.noarch
  Installing       : python3-dns-1.15.0-8.el8.noarch                                                                                               1/1 
Installed: python3-dns-1.15.0-8.el8.noarch
  Running scriptlet: python3-dns-1.15.0-8.el8.noarch                                                                                               1/1 
  Verifying        : python3-dns-1.15.0-8.el8.noarch                                                                                               1/1 

Installed:
  python3-dns-1.15.0-8.el8.noarch                                                                                                                      

Complete!

The same applies to all other Python 3 Libraries.

To use Python 3, just type

python3

Install Python 2.7 on RHEL 8

For some guys with existing software not ready to run on Python 3, RHEL 8 got you covered. It contains the Python 2 stack.

Install Python 2.7 on RHEL 8 in parallel with Python 3 using the command:

sudo yum -y install python2

Confirm:

$ which python2
/usr/bin/python2

To use Python 2.7, type the command:

python2

Set Default Python Version

You should have noted that to use Python 3, the command is python3andpython2 for Python 2. What if your applications are configured to refer to python which is not available system-wide.

$ python
bash: python: command not found...

You can use the alternativesmechanism to enable the unversioned python command system-wide, and set it to a specific version:

Set Python 3 as default:

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

Set Python 2 as default:

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

Running python -V should show default Python version configured

$ python -V
Python 2.7.15

Use Python 2 via python:

$ python
Python 2.7.15 (default, Oct 16 2018, 15:28:01) 
[GCC 8.2.1 20180905 (Red Hat 8.2.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

To reset this configuration and remove the unversioned python command, run:

$ sudo alternatives --auto python

Enjoy using Python for your Development Projects in RHEL 8.