Created
January 23, 2026 17:49
-
-
Save Randy420Marsh/834700c2f3673a73245b94c2940b38b5 to your computer and use it in GitHub Desktop.
Managing Python with Update-Alternatives
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 📘 Manual: Managing Python with Update-Alternatives | |
| The update-alternatives tool creates, removes, maintains, and displays information about the symbolic links comprising the Debian alternatives system. | |
| 1. Register Python Versions (Setup) | |
| Before you can switch between versions, you must register them as "alternatives" for the python3 command. The number at the end represents the priority (higher numbers have higher priority in "auto" mode). | |
| Bash | |
| # Register Python 3.10 (Standard Ubuntu 22.04) | |
| sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1 | |
| # Register Python 3.11 (Your manual install) | |
| sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.11 2 | |
| 2. Switch Active Version (Config) | |
| Use this command to interactively choose which version of Python should be the active default. | |
| Bash | |
| sudo update-alternatives --config python3 | |
| Usage: | |
| A list of registered versions will appear. | |
| Type the Selection number and press Enter. | |
| The version marked with an asterisk * is currently active. | |
| 3. View Status (Display) | |
| To see all registered paths, their current priority, and which version is currently being used, use the --display flag. | |
| Bash | |
| update-alternatives --display python3 | |
| Tip: This is useful for confirming if a path is correct or if the system is in "auto" vs "manual" mode. | |
| 4. Remove a Version (Remove) | |
| If you no longer want a specific version to be an option (or if you made a typo in the path), use the --remove flag. | |
| Bash | |
| # Syntax: sudo update-alternatives --remove <link_group> <path_to_binary> | |
| sudo update-alternatives --remove python3 /usr/local/bin/python3.11 | |
| 5. Reset All Alternatives (Wipe) | |
| If the symlinks become broken or you wish to start over, you can remove the entire python3 group. | |
| Bash | |
| sudo update-alternatives --remove-all python3 | |
| ⚠️ Critical Note for Ubuntu Users | |
| Ubuntu's internal tools (like the terminal and the software updater) are dependent on the specific version of Python that shipped with the OS. | |
| System Default: Python 3.10 | |
| Risk: Leaving Python 3.11 as the "Active" version indefinitely can cause system scripts to crash. | |
| Best Practice: Use update-alternatives to switch to 3.11 for your installation/task, then switch back to 3.10 immediately afterward. | |
| Would you like me to generate a script that automates this "switch, install, and switch back" process for you? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment