Setting Alternatives Path for Python Command in RHEL 8

alternatives: python to /usr/bin/python3

Red Hat Enterprise Linux 8 comes with support for both Python 2 and Python 3. But neither of them is invoked via running python command – you get “command not found” error.

Default Python Version in RHEL 8

Python 3.6 is the default and primary version of Python in RHEL 8. It may need to be istalled, but in my VirtualBox VM installation of RHEL 8 beta it came preinstalled.

Check Python 3 version

Just type python3 to see which version you have:

[greys@rhel8 ~]$ python3
Python 3.6.6 (default, Oct 16 2018, 01:53:53)
[GCC 8.2.1 20180905 (Red Hat 8.2.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>    

Python Command Not Found

If we type python instead of python3, we’ll get the following error:

[greys@rhel8 ~]$ python
bash: python: command not found…

Set Alternatives Path For Python to Python3

There’s a special alternatives method in Red Hat Linux and CentOS, it allows you to select the primary version of a tool when multiple versions are available. Among other things, alternatives command (must be run as root) can create default paths.

This command configures RHEL to invoke /usr/bin/python3 whenever you run python:

[greys@rhel8 ~]$ sudo alternatives --set python /usr/bin/python3
[sudo] password for greys:

That’s it! If you type python again, you’ll see python3 executed instead of getting an error:

[greys@rhel8 ~]$ python
Python 3.6.6 (default, Oct 16 2018, 01:53:53)
[GCC 8.2.1 20180905 (Red Hat 8.2.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>    

Have fun!