Pages

From Python 2 to Python 3: A Guide for Upgrading on CentOS

CentOS is a popular Linux distribution that comes with Python 2 installed by default. However, if you want to use Python 3, you can change the default version by following a few simple steps. In this blog post, we will guide you through the process of changing the default Python version from Python 2 to Python 3 in CentOS.

Step-by-Step Guide

  1. Check the current Python version by running the command:
python --version

This command will display the version of Python currently installed on your system.

  1. Install Python 3 by running the command:
sudo yum install python3

This will install the latest version of Python 3 available in the CentOS repository.

  1. Check the installed Python 3 version by running the command:
python3 --version

This command will display the version of Python 3 you just installed.

  1. Change the symbolic link for /usr/bin/python to point to the newly installed Python 3 by running the command:
sudo ln -sf /usr/bin/python3 /usr/bin/python

This will set Python 3 as the default version when you run the python command.

  1. Verify that Python 3 is the default version by running the command:
python --version

This command should now display the version of Python 3 you just installed.

  1. Update any packages that depend on Python by running the command:
sudo yum update

This will ensure that all packages that require Python are updated to use the new version.

That's it! You have successfully changed the default version of Python from Python 2 to Python 3 in CentOS.

References

  1. How To Install Python 3 on CentOS 7
  2. How to Change the Default Python Version on CentOS

No comments:

Post a Comment

If you have any doubts regarding the post. Please let me know.