Method 1: Using the update-alternatives command
- First, you need to install Python 3.10 on your system. You can do this by running the following command:
sudo apt install python3.10Done Building dependency tree…
Done Reading state information…
Done
E: Unable to locate package python3.10
E: Couldn’t find any package by glob ‘python3.10’
sudo add-apt repository ppa:deadsnakes/ppasudo apt update sudo apt install python3.10This should allow you to install Python 3.10.
- Once Python 3.10 is installed, you can use the
update-alternativescommand to set it as the default Python version. Run the following command:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1This will set Python 3.10 as the default Python version.
- To verify that Python 3.10 is now the default version, run the following command:
python3 --versionThis should output Python 3.10.x.
To check that we have both 3.10 and 3.12 running in our systems,
we can run the sudo apt install python3.10 and sudo apt install python3.12 commands,
we should see something like this:
❯ sudo apt install python3.10
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
python3.10 is already the newest version (3.10.14-1+noble2).
0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.
❯ sudo apt install python3.12
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
python3.12 is already the newest version (3.12.3-1ubuntu0.1).
python3.12 set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.
Method 1 done! Congrats!
Note that downgrading Python may break some packages that depend on the newer version of Python. You may need to reinstall or update these packages to work with Python 3.10.
Also, keep in mind that it’s generally not recommended to downgrade Python, as newer versions often include security patches and bug fixes. If you’re experiencing issues with Python 3.12, it may be better to try to resolve them rather than downgrading to an older version.
Method 2: Using the apt package manager
- First, you need to remove the Python 3.12 package from your system. Run the following command:
sudo apt remove python3.12- Next, you need to install the Python 3.10 package. Run the following command:
sudo apt install python3.10- Once Python 3.10 is installed, you can verify that it’s the default version by running the following command:
python3 --versionThis should output Python 3.10.x
This second method is not recommended since it could break parts of your systems, if you are exploring possibilities to learn, and you are on a testing environment, feel free to try stuff out, but if your environment is a production environment, you may want to explore other options like creating a virtual environment “venv” and using a particular version of python inside that virtual environment without modifying things system-wide.
I hope one of these options works for you!
