Step 1: Update the System
dnf update -y
Step 2: Check for Python Preinstalled
RHEL 9 usually comes with Python 3 pre-installed. Check the current version:
python3 –version
Step 3: Install Python (If Not Already Installed)
RHEL 9 provides Python 3 through its default package manager.
dnf install python3 -y
Step 4: Verify Python Installation
Check the installed version to confirm:
python3 –version
Step 5: Install Development Tools (Optional but Recommended)
Development tools are required for building Python packages with native dependencies.
dnf groupinstall “Development Tools” -y
dnf install gcc python3-devel -y
Step 6: Set Python3 as Default (Optional)
If python3 does not default to python, set it up manually:
Check current alternatives:
alternatives –config python
If no alternatives are configured, set one:
alternatives –install /usr/bin/python python /usr/bin/python3 1
alternatives –set python /usr/bin/python3
Step 7: Install pip (Python Package Manager)
dnf install python3-pip -y
Verify the installation:
pip3 –version
Step 8: Install Virtual Environment (Optional but Recommended)
dnf install python3-virtualenv -y
Create a virtual environment:
python3 -m venv myenv
source myenv/bin/activate
Step 9: Test Installation
Create a simple Python script to ensure Python is working:
vi test.py
Add the following code:
print(“Python installation successful on RHEL 9!”)
Run the script:
python3 test.py