How to Install Python3 RHEL6

Note: This also works on CentOS Version 6. The procedure was fully tested as working on Python3 RHEL6 and CentOS6 (March 2023)

A large number of operating system applications require Python. Out of the box, Red Hat 6 versions only support Python2.6, and Red Hat 7 versions only support Python2.7. Both of these versions are deprecated as of January 2021 despite RHEL6 being in an extended life phase. Python will still work, but Red Hat will provide no further support or security updates.

In RHEL6, if you type yum install python3, you will get an error that the file does not exist.

ShellScript
yum install python3
ShellScript

Error Output:

Example Error
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
No package python3 is available.
Error: Nothing to do
ShellScript

The problem is that the default yum repositories for Red Hat 6 are not being updated with the latest versions of Python, but the new versions are available in the Red Hat Software Collections repo, however, this repo is not enabled by default.

If you were to try a yum install python 3, python 3.8, a major release, or the latest release, the job would fail with this error message.

Therefore, you have 2 options.

  • Install Python from the source code.
  • Install Python from Red Hat Software Collections.

How to install Python 3.9 from the source code

The cleanest way to install Python 3.9 is to install it from the source code.

This is how you do it:

Step 1 – Yum Update and Install Pre-Reqs

If you have any issues updating yum due to CentOS/RHEL6 going to end of life, follow this procedure to fix the problem.

ShellScript
yum update -y
yum groupinstall "Development Tools" -y
yum install wget zlib-devel -y
ShellScript

Step 2 – Download the latest version of Python from Python.org

Check the Python Website for the latest version for your operating system. Python is updated regularly, so it’s more than likely that there is a newer edition already.

ShellScript
wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tar.xz
ShellScript

Step 3 – Extract the Python download.

ShellScript
tar xvf Python-3.9.1.tar.xz
ShellScript

Step 4 – Navigate to the new folder

ShellScript
cd Python-3.9.1
ShellScript

Step 5 – Prepare the source code for the build; this will be a local install with PIP baked in

ShellScript
./configure --prefix=/opt/local --with-ensurepip=install
./configure --enable-optimizations
ShellScript

Step 6 – Install Python

Please note that we will use ALT INSTALL and RHEL6 uses Python2 for system applications such as yum

ShellScript
make altinstall
ShellScript

You can use the latest version of python by prefixing the commands with python3.9

ShellScript
python3.9 --version
Python 3.9.1
ShellScript

Or you can add create an alias for Python3.9 and Pip.39

ShellScript
alias python="/usr/local/bin/python3.9"
alias pip="/usr/local/bin/pip3.9"
ShellScript

You will see out like this:

ShellScript
which pip
alias pip='/usr/local/bin/pip3.9'
/usr/local/bin/pip3.9

which python
alias python='/usr/local/bin/python3.9'
/usr/local/bin/python3.9
ShellScript

You must exit the shell and log back in to make the change.

Install Python36 from the Red Hat Software Collection Repo

To install Python from Red Hat Software Collections on a Red Hat Enterprise Linux (RHEL) system, follow these steps:

Step1 – Enable RHEL Software Repo

Enable the Red Hat Software Collections repository by running the following command:bash

ShellScript
sudo subscription-manager repos --enable rhel-server-rhscl-7-rpms
ShellScript

Note that the repository name may differ depending on the version of RHEL you are using.

Step 2 – Instal RHEL Software Utility

Install the Software Collections Utility package by running the following command:

ShellScript
sudo yum install scl-utils
ShellScript

Step 3 – Install Python 36

Install Python 3 by running the following command:

ShellScript
sudo yum install rh-python36
ShellScript

This command will install Python 3.6 from the Red Hat Software Collections repository.

Step 4 – Enable Python36 on the shell

To use Python 3.6, you will need to enable the Software Collection by running the following command:

ShellScript
scl enable rh-python36 bash
ShellScript

This command will start a new Bash shell with the Software Collection enabled.

Alternatively, you can also use the following command to run Python 3.6 directly:

ShellScript
scl enable rh-python36 'python3.6' 
ShellScript

This will launch the Python 3.6 interpreter.

That’s it! You should now have Python 3.6 installed from the Red Hat Software Collections repository on your RHEL system.

Thanks for taking the time to read this article. if you have any questions or feedback, please write in the comment section below.

Elsewhere On TurboGeek:  Understanding Red Hat Permissions

You may also like...

9 Responses

  1. JG says:

    I ran into an issue on RHEL6.

    All the listed prerequisites are present, but I still get:

    [localhost][~/Python-3.9.1] # ./configure –prefix=/opt/local –with-ensurepip-install
    configure: WARNING: unrecognized options: –with-ensurepip-install
    checking build system type… x86_64-pc-linux-gnu
    checking host system type… x86_64-pc-linux-gnu
    checking for python3.9… no
    checking for python3… no
    checking for python… python
    checking for –enable-universalsdk… no
    checking for –with-universal-archs… no
    checking MACHDEP… “linux”
    checking for gcc… gcc
    checking whether the C compiler works… no
    configure: error: in `/root/Python-3.9.1′:
    configure: error: C compiler cannot create executables
    See `config.log’ for more details

  2. Alex Rodenberg says:

    Have you tested this ? Python 3.7+ needs a newer openssl / zlib than centos 6 has.. so you would need to compile them too.

  3. Ksenia says:

    Thank you very much for your guide. With its help, even with my little experience I was able to install Pythom 3.9.17 on Red Hat Enterprise Linux 6.10.

Leave a Reply

Your email address will not be published. Required fields are marked *