How to change python default version from 2.7 to 3.7 on RHEL 7.

Installed python on RHEL7 virtual machine by following this https://tecadmin.net/install-python-3-7-on-centos/

When I check python version it still prints old version.

  • 4
    You almost certainly do not want to do this globally. It WILL break your system. – Austin Hemmelgarn Sep 12 '18 at 19:32
  • I'd start by trying /usr/sbin/alternatives --config python – Cupcake Protocol Sep 12 '18 at 20:58
  • 2
    It would not be advised to replace the base python version as it will break your RHEL system (all base software expecting Python 2.7 will cease to work, such as yum), but to instead keep the base version for the system to use and install the newer version in a way that does not affect the base version. RedHat has an option to install python3 this way using what they call Software Collections. – GracefulRestart Sep 12 '18 at 21:20

As others have said above in the comments, RHEL 7 and its derivatives depend on Python 2 at a very deep level. You simply cannot safely replace Python 2 with 3.

Even if that were not the case, your question is based on an incorrect premise, being that replacing Python 2 with Python 3 is a good idea in the first place. You should always call Python 3 as python3, since that insulates you from this problem. Scripts that assume Python 2 will call it as python in shebang lines and such, so there is not in fact a conflict between the two if your binary Python packages are built properly.

That “if” can bite you: some packagers have created Python 3 packages with a /usr/bin/python or similar, which creates a conflict. These packages are ignoring the standard advice, which allows both to be installed in parallel.

As for actually getting a Python 3 package for RHEL 7, that’s well covered in another answer on Stack Overflow.


I would recommend the alternatives solution

My commands wold be.


alternatives --list | grep -i python
alternatives --install /usr/bin/python python /usr/bin/python2.7 1
alternatives --install /usr/bin/python python /usr/bin/python3.6 2
alternatives --install /usr/bin/python python /usr/local/bin/python3.7 3
alternatives --config python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.