How to Install Python3 (3.12.1) on RHEL6

Note: The procedure was fully tested on Python 3.12.1 RHEL6 and CentOS6 (December 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.

Bash
yum install python3

Error Output:

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

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.12.1 from the source code

The cleanest way to install Python 3.12.1 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 the end of life, follow this procedure to fix the problem.

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

Step 2 – Install GCC-8 Developer Tools

This step is essential for Python version 3.8.x upwards since the new versions of GCC are needed to compile Python on CentOS6/RHEL6

Create the following repo and add the contents below:

Bash
vi /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo

Now add this Content:

Bash
[centos-sclo-rh]
name=CentOS-6 - SCLo rh
baseurl=http://vault.epel.cloud/centos/6/sclo/$basearch/rh/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-rh-testing]
name=CentOS-6 - SCLo rh Testing
baseurl=http://buildlogs.centos.org/centos/6/sclo/$basearch/rh/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-rh-source]
name=CentOS-6 - SCLo rh Sources
baseurl=http://vault.epel.cloud/centos/6/sclo/Source/rh/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-rh-debuginfo]
name=CentOS-6 - SCLo rh Debuginfo
baseurl=http://debuginfo.centos.org/centos/6/sclo/$basearch/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

Now create the following repo and add the contents below:

Bash
vi /etc/yum.repos.d/CentOS-SCLo-scl.repo

Now Add this Content

Bash
[centos-sclo-sclo]
name=CentOS-6 - SCLo sclo
baseurl=http://vault.epel.cloud/centos/6/sclo/$basearch/sclo/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-sclo-testing]
name=CentOS-6 - SCLo sclo Testing
baseurl=http://buildlogs.centos.org/centos/6/sclo/$basearch/sclo/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-sclo-source]
name=CentOS-6 - SCLo sclo Sources
baseurl=http://vault.epel.cloud/centos/6/sclo/Source/sclo/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-sclo-debuginfo]
name=CentOS-6 - SCLo sclo Debuginfo
baseurl=http://debuginfo.centos.org/centos/6/sclo/$basearch/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

Finally, run the yum update and then Install GCC-8 dependencies

Bash
yum update -y
yum install devtoolset-8-gcc devtoolset-8-gcc-c++ -y
export CC=/opt/rh/devtoolset-8/root/usr/bin/gcc

Note: If you get error like this:

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

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

It is recommended to use the XZ Compressed source tarball.

Bash
wget https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tar.xz

You should see the following output:

Bash
wget https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tar.xz
--2023-12-11 17:07:20--  https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tar.xz
Resolving www.python.org... 146.75.32.223, 2a04:4e42:8f::223
Connecting to www.python.org|146.75.32.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 20583448 (20M) [application/octet-stream]
Saving to: `Python-3.12.1.tar.xz.1'

100%[===========================================================>] 20,583,448  22.8M/s   in 0.9s    

2023-12-11 17:07:21 (22.8 MB/s) - `Python-3.12.1.tar.xz.1' saved [20583448/20583448]

Step 3 – Extract the Python download.

Bash
tar xvf Python-3.12.1.tar.xz

Navigate to the new folder

Bash
cd Python-3.12.1

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

The configure script is usually the first step in this process, responsible for setting up the build environment according to specified options and system settings. The options provided after ./configure tailor the build process according to specific requirements or optimizations desired for the resulting software installation.

Bash
./configure --prefix=/opt/local --with-ensurepip=install

Bash
./configure --enable-optimizations

You should see output similar to this:

Bash
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-embed.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/Setup.bootstrap
config.status: creating Modules/Setup.stdlib
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
config.status: pyconfig.h is unchanged
configure: creating Modules/Setup.local
configure: creating Makefile

Step 6 – Install Python

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

The command make altinstall is to install Python from its source code.

Bash
make altinstall

Note: The make command will take several minutes to complete. I used a modest VPS with 4GB RAM and 2 CPUs, and it took about 15 minutes to complete.

Bash
/usr/bin/install -c -m 644 ./Misc/python.man \
		/usr/local/share/man/man1/python3.12.1
if test "xupgrade" != "xno"  ; then \
		case upgrade in \
			upgrade) ensurepip="--altinstall --upgrade" ;; \
			install|*) ensurepip="--altinstall" ;; \
		esac; \
		 ./python -E -m ensurepip \
			$ensurepip --root=/ ; \
	fi
Looking in links: /tmp/tmpx72ujmtm
Processing /tmp/tmpx72ujmtm/pip-23.2.1-py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-23.2.1

You can use the latest version of Python by prefixing the commands with python3.12.1

Bash
python3.12 --version
Python 3.12.1

Or you can create an alias for Python3.12.1 and Pip.x

You will see output like this:

Bash
alias python="/usr/local/bin/python3.12"
alias pip="/usr/local/bin/pip3.12"

Bash
which pip
alias pip='/usr/local/bin/pip3.12'
/usr/local/bin/pip3.12

which python
alias python='/usr/local/bin/python3.12'
/usr/local/bin/python3.12

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:

Elsewhere On TurboGeek:  Learning Arcserve Backup and Restore (BMR)

Step1 – Enable RHEL Software Repo

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

ShellScript
sudo subscription-manager repos --enable rhel-server-rhscl-6-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.

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

13 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.

  4. Lucas says:

    The article doesn’t metion source /opt/rh/devtoolset-8/enable which actually enables the GCC for the current session.

Leave a Reply

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

Translate »