How to Switch Between Python Versions

A Step-By-Step Guide for Reverting to Older Python Versions

To revert to an older Python version and set it as the default, you can use update-alternatives on Debian-based systems or manipulate symbolic links. Here's how:

Using update-alternatives (Debian-based like Ubuntu)

If you've set up multiple Python versions using update-alternatives, you can switch between them by running:

sudo update-alternatives --config python3

You'll get a menu to choose the Python version. Select the one you want.

If you've manually changed the symbolic link for Python, you can revert it like this:

  1. Remove the existing link:

     sudo rm /usr/bin/python3
  2. Create a new link pointing to the original Python executable:

     sudo ln -s /usr/bin/python3.x /usr/bin/python3

Replace python3.x with the original version you want, like python3.8.

Bash Script Example

If you want to automate it, you could write a Bash script:


# Using update-alternatives
sudo update-alternatives --config python3

# OR using symbolic links
# sudo rm /usr/bin/python3
# sudo ln -s /usr/bin/python3.x /usr/bin/python3

echo "Python version switched."

Remember to give execute permissions to the script:

chmod +x

Then run it:


That should set your Python version back to the original one.