167 words
1 minutes
Set default version for python
2024-06-03

Set default version for python in debina/ubuntu machines.#

  1. Check Installed Python Version
  2. Install the Desired Python Version (if not already installed)
  3. Create a symbolic link to point the python command to python3.
  4. Verify that the python command points to the correct Python version
python3 --version
sudo apt update && sudo apt install python3.12
sudo ln -s /usr/bin/python3 /usr/bin/python
python --version

Update Alternatives (Optional)#

  1. Add the Python versions to the alternatives system
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 2

2.Configure the default Python version

sudo update-alternatives --config python
  1. Verify the Alternatives Configuration
python --version
NOTE

By following these steps, you can ensure that the python command on your Ubuntu system points to your desired Python 3 version. This can help standardize scripts and commands that rely on the python command, ensuring they use the correct Python interpreter.

Conclusion#

That’s it! You’ve learnt, how to setup the default version for python in linux machines. If you have any doubts/issues/errors with the above contents, feel free to contact me. Cheers, Happy learning.