How to Use Python 3.X (3.9, 3.10, or 3.11) as Default for “python3” in Linux?

Ready to embrace the power of Python 3.11 as your default Python3 version? 🐍 Let’s make it happen! Just follow these simple steps:

1️⃣ First, let’s check your current default Python version. Open your terminal and run the following command:

python3 --version

In my AWS instance, the command python3 pointed to my installed Python version 3.9 instead but I wanted it to point to 3.11.

2️⃣ Next, we’ll use update-alternatives to create symbolic links to Python 3.10 and Python 3.11. You can replace it with your specific Python versions as you see fit. Each is identified using an integer value 1 and 2.

Enter these commands one by one:

The first command sets the Python version 3.9 to identifier 1:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1

The second command sets the Python version 3.11 to identifier 2:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2

3️⃣ Now, it’s time to choose Python 3.11 as your go-to Python3! πŸ”₯ Type the command below:

sudo update-alternatives --config python3

Now you can type in the identifier of the Python version you want as default for the command python3. In my case, it would be 2 because I want python3.11. See here:

✨ Ta-da! You’ve successfully set up Python 3.11 as your default version! πŸŽ‰

Feel free to switch between Python versions at any time using the commands provided above. Remember, with great power comes great responsibility: after switching to 3.11, make sure to check if all your essential apps are working smoothly. πŸ•΅οΈβ€β™€οΈ

πŸ’‘ Recommended: How to Check Your Python Version?