Photo by Clément Hélardot on Unsplash
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.
Using Symbolic Links (Generic)
If you've manually changed the symbolic link for Python, you can revert it like this:
Remove the existing link:
sudo rm /usr/bin/python3
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:
#!/bin/bash
# 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 switch_python_version.sh
Then run it:
./switch_python_version.sh
That should set your Python version back to the original one.