How To Recover Yum After Upgrading Python 2.6.6 on CentOS 6

Updated on November 21, 2023
How To Recover Yum After Upgrading Python 2.6.6 on CentOS 6 header image

The majority, if not all of Vultr’s one-click applications are based on CentOS 6.x. In this version of CentOS, the default Python version is 2.6.6.

In some cases, using a newer version of Python is required. As such, upgrading the default Python version to 2.7.x or 3.x becomes necessary.

Upgrading Python to a newer version is a relatively simple; however, if not done properly, some Python-dependant applications such as yum may cease to function.

In this article we will be covering the process of restoring yum’s functionality after upgrading from Python 2.6.6 to Python 3.5.1 on CentOS 6 x64.

Prerequisites

To test the instructions in this article, you need to deploy a fresh Vultr CentOS 6 x64 server instance and log in from your SSH terminal using a sudo user.

Upgrade the built-in Python 2.6.6 to Python 3.5.1

Before the upgrade, you can have a look at the current version of Python:

python -V

The system will report the installed Python version as: Python 2.6.6.

Update system and install dependencies:

sudo yum update
sudo yum install gcc

Download and compile Python 3.5.1:

cd /opt
sudo wget --no-check-certificate https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
sudo tar -xvf Python-3.5.1.tgz
cd Python-3.5.1
sudo ./configure --prefix=/usr/local && sudo make && sudo make install

After the compilation, use the following command to confirm your installation:

/usr/local/bin/python3.5 -V

The system will report the installed Python version as: Python 3.5.1.

Set the default version of Python on the system

To use Python 3.5.1 as your Default Python Version, you would need to specify the absolute path for its binary as follows:

sudo mv /usr/bin/python /usr/bin/python2.6.6
sudo ln -s /usr/local/bin/python3.5 /usr/bin/python

To confirm:

python -V

And now, the default Python version is set to 3.5.1.

Restore Yum’s functionality

On CentOS 6.x, yum relies on Python 2.6.6 by default. In order to change that, you would need to adjust the configuration file to use the new version as follows:

sudo vi /usr/bin/yum

Modify the first line from

#!/usr/bin/python

to

#!/usr/bin/python2.6.6

Save and quit:

:!wq

This concludes our tutorial. Thank you for reading.