How to Install Python3 on RHEL6

Reading Time: 2 minutes

Python is required by a large number of operating system applications. 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 there will be no further support or security updates provided by Red Hat.

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

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 latest release, the job would fail with this error message.

Therefore you have 2 options

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

How to install Python 3.9 from source

Step 1 – Run yum update and install pre-reqs

yum update -y
yum groupinstall "Development Tools" -y

yum install zlib-devel -y

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

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

Step 3 – Extract the Python download

tar xvf Python-3.9.1.tar.xz

Step 4 – Navigate to the new folder

cd Python-3.9.1

Step 5 – Prepare the sourcecode for the build, this will be a local install with PIP baked in

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

Step 6 – Install Python, please note that we will use an ALT INSTALL and RHEL6 uses Python2 for system applications such as yum

make altinstall

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

[[email protected] ~]# python3.9 --version
Python 3.9.1

Or you can add create an alias

alias python="/usr/local/bin/python3.9"

You will need to exit the shell and log back in to make the change

That’s it, thanks for taking the time to read this article. if you have any questions or feedback please write in the comment section below.

You may also like...

Leave a Reply

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