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.
yum install python3
ShellScriptError Output:
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
No package python3 is available.
Error: Nothing to do
ShellScriptThe 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.
yum update -y
yum groupinstall "Development Tools" -y
yum install wget zlib-devel -y
ShellScriptStep 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.
wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tar.xz
ShellScriptStep 3 – Extract the Python download.
tar xvf Python-3.9.1.tar.xz
ShellScriptStep 4 – Navigate to the new folder
cd Python-3.9.1
ShellScriptStep 5 – Prepare the source code for the build; this will be a local install with PIP baked in
./configure --prefix=/opt/local --with-ensurepip=install
./configure --enable-optimizations
ShellScriptStep 6 – Install Python
Please note that we will use ALT INSTALL and RHEL6 uses Python2 for system applications such as yum
make altinstall
ShellScriptYou can use the latest version of python by prefixing the commands with python3.9
python3.9 --version
Python 3.9.1
ShellScriptOr you can add create an alias for Python3.9 and Pip.39
alias python="/usr/local/bin/python3.9"
alias pip="/usr/local/bin/pip3.9"
ShellScriptYou will see out like this:
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
ShellScriptYou 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
sudo subscription-manager repos --enable rhel-server-rhscl-7-rpms
ShellScriptNote 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:
sudo yum install scl-utils
ShellScriptStep 3 – Install Python 36
Install Python 3 by running the following command:
sudo yum install rh-python36
ShellScriptThis 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:
scl enable rh-python36 bash
ShellScriptThis 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:
scl enable rh-python36 'python3.6'
ShellScriptThis 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.
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
If you already have pip, you may need to use the command
param -with-ensurepip=upgrade instead of -with-ensurepip=install
If you are still having issues send me the output from the config.log
I have just tested the procedure end-to-end and it worked perfectly.
there is a typo in that command, the option must be –with-ensurepip=install
thank you for the feedback, I have updated the site.
Have you tested this ? Python 3.7+ needs a newer openssl / zlib than centos 6 has.. so you would need to compile them too.
Thank you for the heads up, I will check and validate over the coming days.
Any news covering this issue? Currently having problems about this
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.