Bookmark this page

Guided Exercise: Managing Python Versions in RHEL 8

In this exercise, you will ensure that both Python 3 and Python 2 are installed on a server, and use the alternatives command to control whether an unversioned Python executable is available and which version of Python it uses.

Outcomes

You should be able to install Python 2.7 and Python 3.6, and configure the python command to link to one of their binaries.

  1. On servera, verify that the python command does not exist by default on Red Hat Enterprise Linux 8.

    1. Log in to servera then become the root user.

      [student@workstation ~]$ ssh servera
      [student@servera ~]$ sudo -i
      [root@servera ~]# 
    2. Verify that the python command does not exist by default.

      [root@servera ~]# which python
      /usr/bin/which: no python in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
  2. Install Python 2.7 and verify that it is available.

    1. Use Yum to install Python 2.7 using the python27 module.

      [root@servera ~]# yum module install python27
      ...output omitted...
      Is this ok [y/N]: y
      ...output omitted...
    2. Verify that Python 2.7 is available.

      [root@servera ~]# python2 -V
      Python 2.7.15
  3. Install Python 3.6 and verify that it is available.

    1. Use Yum to install Python 3.6 using the python36 module.

      [root@servera ~]# yum module install python36
      ...output omitted...
      Is this ok [y/N]: y
      ...output omitted...
    2. Verify that Python 3.6 is available.

      [root@servera ~]# python3 -V
      Python 3.6.8
  4. Use the alternatives command to enable /usr/bin/python3. When done, log off from servera.

    1. Use the alternatives command to point /usr/bin/python to /usr/bin/python3.

      [root@servera ~]# alternatives --config python
      There are 3 programs which provide 'python'.
      
        Selection    Command
      -----------------------------------------------
      *+ 1           /usr/libexec/no-python
         2           /usr/bin/python3
         3           /usr/bin/python2
      
      Enter to keep the current selection[+], or type selection number: 3
    2. Verify that the python command uses Python 3.6.

      [root@servera ~]# python -V
      Python 3.6.8
    3. Log off from servera.

      [root@servera ~]# exit
      [student@servera ~]$ exit
      [student@workstation ~]$ 

This concludes the guided exercise.

Revision: rh354-8.0-0e36520