Header Ads

How to Change Default Python Version in Ubuntu - A Step-by-Step Guide for 2026

Every Linux based operating system (OS) such as Ubuntu come pre-installed with many libraries, python is one such example. However, the latest version compatibility of every library depends on the version of OS itself. For example, Ubuntu 24.04 version is compatible with python version 3.12 or below. You cannot install the higher version than that because it's not supported by the OS version. Lower versions are supported but, the question is: How can you change between compatible versions within Ubuntu environment without causing any kind of disruption to the OS currently working operations according to the demands of your projects?

Today, I shall be demonstrating a detail process of changing between compatible python versions within Ubuntu 24.04 system. I am using Windows Subsystem for Linux (WSL) for my Ubuntu environment. I will be using python library "pyenv".

 


Prerequisites:

Before proceeding any further in this article, following are some of the many prerequisites for this article:
  1. Enable Windows Subsystem for Linux (WSL).
  2. Update WSL to WSL 2.
  3. Install Ubuntu 24.04 LTS Distro for WSL. 
  4. Knowledge of Working in Terminal Environment.
     

You can download complete solution files that I have created in order to install the pyenv python library for changing between different python version. My provided solution contains Ubuntu environment shell script for installing & changing python version using pyenv library along with windows powershell script file for downloading the missing require certificates for pyenv python library installation. 

Let's begin now.

1) The first step is to execute the windows powershell script file in order to download the missing require certificates for installation of pyenv library. For this you need to open windows powershell as administrator and change to the directory location of the provided powershell script file. Then use below command to download the missing certificates i.e.

 

 
 2) Next start the Ubuntu terminal using WSL commands. I am using Ubuntu 24.04 WSL distro. If you have not already enabled WSL then checkout How to Enable WSL with Ubuntu Distro on Windows Machine.
 
 
3) You can either copy & execute directly my provided shell script file to/on Ubuntu file system or you can follow this article step by step.
 
 
4) Now, execute below set of commands to install the require missing library packages for pyenv installation. i.e.

 
 

5)
 In the Next step, execute the below set of command to copy the missing downloaded certificates into Ubuntu file system i.e.
 
 


6) To install and configure pyenv python library environment, execute the below set of commands. The advantage of pyenv library is that you can manage multiple python versions easily without creating disruptions or causing any conflicts to the core Ubuntu environment operations whenever you require to switch between python versions base on your project requirements i.e.

 



7) Execute below command to check your Ubuntu system default python latest compatible version i.e.




8) Now install compatible python version of your choice with the below command. In my case I am installing python version 3.10.19. Make sure to be precise about the python version you want to install i.e.




9) You can check all the python versions that pyenv library manages by executing the below command i.e.




10) We are almost done! Now there are 3 different ways by which you can change python version using pyenv library within Ubuntu environment i.e.
  1. Globally: I don't recommend this option because it can interfere with Ubuntu environment core.
     
  2. Locally: With this you can change python version more specific to your project environment without any interference with the core environment.

  3.  At Runtime: I highly recommend this option simply because this ensures that your python version has not permanently changed but only when needed and at the closure of the terminal everything resets back to default.

11) So to change python version at runtime using pyenv library, execute below set of command i.e.



12) Now check the python current version by executing below command. You will see that your desire python version is now in power i.e.




Conclusion

In this article, you will learn about the detail process of changing between compatible python versions within Ubuntu 24.04 system. You will learn about python library "pyenv" along with its installation process. You will also learn about the downloading process of the missing certificates require to install the pyenv library. Finally, you will learn to change python version at runtime without causing any errors & conflicts for the core Ubuntu environment operations along with what other options pyenv library supports for switching between different python versions.


Related Articles