Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

How to change the meaning of python and python3 on RHEL

September 30, 2025
Tomáš Hrnčiar
Related topics:
LinuxProgramming languages & frameworksPython
Related products:
Red Hat Enterprise Linux

Share:

    Historically, administrators of Red Hat Enterprise Linux (RHEL) used the alternatives command to change the system's default python3 interpreter. This method was technically a challenge to support. Because the system Python is deeply integrated into RHEL, changing its version can break critical components. This post explains why alternatives is unsupported in RHEL 9 and later, and offers a safer alternative.

    Python is a vital system component

    Numerous core RHEL components are tightly coupled with the system's version of Python. One prominent example is dnf, the package manager that installs and updates applications. It's a Python application and relies on the Python version it was tested with. An unauthorized change to the system's default Python environment could render a tool like dnf inoperable, effectively crippling your ability to manage software on the system, which could lead to a broken operating system. Other critical tools, from firewall managers to system initializers and printer drivers, also often depend on the default system Python and could fail unexpectedly should the Python version unexpectedly change.

    Even though RHEL 9 was released in 2022, some users still ask how to change what gets executed when the python3 command is issued. For example, a user might want to configure a system to run /usr/bin/python3.11 rather than, for instance, /usr/bin/python3.9 when python3 is called.

    The best solution is to keep the system Python untouched, and instead create a symbolic link that redefines python3 on your system to your desired Python interpreter. This has zero impact on system packages or other users. It's also easy to reverse by simply removing the symbolic link file.

    As root you can do:

    # sudo ln -s /usr/bin/python3.11 /usr/local/bin/python3
    # python3 --version
    Python 3.11.11
    # ls -la /usr/local/bin/python*
    lrwxrwxrwx. 1 root root 19 Jun 23 09:06 /usr/local/bin/python3 -> /usr/bin/python3.11
    # echo $PATH
    /root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin

    When the symbolic link is created by root, it is also available for other users and services on the system.

    As a regular user:

    $ ln -s /usr/bin/python3.11 ~/.local/bin/python3
    $ python3 --version
    Python 3.11.11
    $ ls -laG ~/.local/bin/python3
    lrwxrwxrwx. 1 tux 19 Jun 24 05:41 /home/tux/.local/bin/python3 -> /usr/bin/python3.11
    $ echo $PATH
    /home/tux/.local/bin:/home/tux/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

    You can safely do the same with the python command.

    Both /usr/local/bin/ and ~/.local/bin/ are part of the default PATH environment variable, so the python3 command will always use a symbolic link defined there.

    Use env in scripts for portability

    In your scripts, you can use #!/usr/bin/env python3 instead of hard-coding the path #!/usr/bin/python3. This ensures improved script portability.

    Different systems (or even different users on the same system) might have the same program installed in different locations. For example:

    • On a standard Linux system, Python might be in /usr/bin/python3
    • A user might have a new version installed in a different location.
    • A developer might use a virtual environment (venv), which puts a python3 executable in a project-specific bin directory and prepends that to the PATH.

    A script with a hard-coded path like #!/usr/bin/python3 uses the system Python in all but the first case.

    A script starting with #!/usr/bin/env python3 handles all these scenarios. It also respects the user's configured environment. When a developer has intentionally placed a specific version of Python first in their PATH, env finds it and uses that version. This allows users to control which interpreter runs a script without modifying the script itself.

    The art of managing interpreters

    Your Linux system can help you manage the version of Python and other popular programming languages and interpreters. Should you wish to override the default settings, there are tools built into Linux to let you do that in a safe and portable way. Use env in your scripts, venv while developing Python applications, maintain your PATH, and use symlinks for targeted overrides.

    Related Posts

    • How to install multiple versions of Python on Red Hat Enterprise Linux

    • Making memcpy(NULL, NULL, 0) well-defined

    • How to deploy a Flask application in Python with Gunicorn

    • A beginner's guide to Python containers

    • How to use a Python multiprocessing module

    • How to manage Python dependencies in Ansible execution environments

    Recent Posts

    • How to change the meaning of python and python3 on RHEL

    • vLLM or llama.cpp: Choosing the right LLM inference engine for your use case

    • How to implement and monitor circuit breakers in OpenShift Service Mesh 3

    • Analysis of OpenShift node-system-admin-client lifespan

    • What's New in OpenShift GitOps 1.18

    What’s up next?

    Whether you're deploying to the cloud, managing systems, or working with containers, the Red Hat Enterprise Linux 10 cheat sheet provides the key information you need for executing essential commands, image building, and system management.

    Get the cheat sheet
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue