Installing Python 3 on RHEL - Stack Overflow
RHEL8 Python Version Management
How to install Python 3.8.1 on RHEL 8? - Stack Overflow
How to upgrade Python 3 on Linux RHEL? - Stack Overflow
Installing from RPM is generally better, because:
- you can install and uninstall (properly) python3.
- the installation time is way faster. If you work in a cloud environment with multiple VMs, compiling python3 on each VMs is not acceptable.
Solution 1: Red Hat & EPEL repositories
Red Hat has added through the EPEL repository:
- Python 3.4 for CentOS 6
- Python 3.6 for CentOS 7
[EPEL] How to install Python 3.4 on CentOS 6
sudo yum install -y epel-release
sudo yum install -y python34
# Install pip3
sudo yum install -y python34-setuptools # install easy_install-3.4
sudo easy_install-3.4 pip
You can create your virtualenv using pyvenv:
pyvenv /tmp/foo
[EPEL] How to install Python 3.6 on CentOS 7
With CentOS7, pip3.6 is provided as a package :)
sudo yum install -y epel-release
sudo yum install -y python36 python36-pip
You can create your virtualenv using pyvenv:
python3.6 -m venv /tmp/foo
If you use the pyvenv script, you'll get a WARNING:
$ pyvenv-3.6 /tmp/foo
WARNING: the pyenv script is deprecated in favour of `python3.6 -m venv`
Solution 2: IUS Community repositories
The IUS Community provides some up-to-date packages for RHEL & CentOS. The guys behind are from Rackspace, so I think that they are quite trustworthy...
https://ius.io/
Check the right repo for you here:
https://ius.io/setup
[IUS] How to install Python 3.6 on CentOS 6
sudo yum install -y https://repo.ius.io/ius-release-el6.rpm
sudo yum install -y python36u python36u-pip
You can create your virtualenv using pyvenv:
python3.6 -m venv /tmp/foo
[IUS] How to install Python 3.6 on CentOS 7
sudo yum install -y https://repo.ius.io/ius-release-el7.rpm
sudo yum install -y python36u python36u-pip
You can create your virtualenv using pyvenv:
python3.6 -m venv /tmp/foo
It is easy to install python manually (i.e. build from source):
Download (there may be newer releases on Python.org):
$ wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tar.xzUnzip
$ tar xf Python-3.* $ cd Python-3.*Prepare compilation
$ ./configureBuild
$ makeInstall
$ make installOR if you don't want to overwrite the
pythonexecutable (safer, at least on some distrosyumneedspythonto be 2.x, such as for RHEL6) - you can installpython3.*as a concurrent instance to the system default with analtinstall:$ make altinstall
Now if you want an alternative installation directory, you can pass --prefix to the configurecommand.
Example: for 'installing' Python in /opt/local, just add --prefix=/opt/local.
After the make install step: In order to use your new Python installation, it could be, that you still have to add the [prefix]/bin to the $PATH and [prefix]/lib to the $LD_LIBRARY_PATH (depending of the --prefix you passed)
I have a question about yum/dnf dependencies. Our security team’s software (Rapid 7) is flagging a lot of instances as having vulnerable Python versions installed. This is because RHEL8 uses Python 3.6 by default. I know we can install newer versions of Python, like 3.11, but is there a way to set that version as the default for any python3 dependency? Example: If I run yum install Ansible on a RHEL8 host yum will list python3.6 as a dependency and install it even if Python 3.11 is already installed. Messing around with Alternatives doesn’t seem to do anything for yum dependencies.
Edit: thanks all. Going to work with our Security team to have Rapid 7 ignore this.
Below command worked for me.
sudo dnf install python3.8 -y
I wanted to use python3.8 and removed old python3.6 and installed python3.8 using above command
command to remove python3.6
sudo dnf remove python3.6 -y
Sharing what worked for me. Worked for me on Enterprise RHEL 7.
#-> python --version
Python 2.7.5
#-> yum install rh-python38
#-> scl enable rh-python38 bash
#-> python --version
Python 3.8.0
But you will have enter into the scl shell everytime as the default shell would still be Python 2.7. To make this permanent, I had to
Add this to my ~/.bash_profile
source /opt/rh/rh-python38/enable