How to Install Python 3.12 on Ubuntu 24.04 - Complete Beginner’s Guide

By Muntashah
How to Install Python 3.12 on Ubuntu 24.04

It doesn’t matter if you are a first-timer or an old user of the Linux ecosystem; Ubuntu 24.04 LTS is the best operating system to benefit from the latest advancements in Linux. In fields such as Data Analytics/ Interpretation and Machine Learning, Ubuntu is the operating system (OS) of many popular frameworks, including OpenCV, TensorFlow, Keras, PyTorch, Kubeflow, etc. It allows you to easily set up ML environments right out of the box.

This guide will discuss a step-by-step process for downloading and installing Python 3.12 on Ubuntu 24.04. Continue reading!

How To Install Python 3.12 On Ubuntu 24.04

Python 3.12 is the stable version and comes with rich features, such as more flexible f-string parsing, Per-Interpreter GIL, new type annotation syntax for generic classes, Linux perf profiler support, and more. You can easily install Python in Ubuntu using the popular Deadsnakes PPA or by building from the source. In this tutorial, we have chosen to install it using the Deadsnakes PPA.

In our case, we have already deployed an instance on our node. Ubuntu 24.04 comes with Python 3.10 installed. To confirm this, you can run the command python 3- V in the command prompt. So, the first thing we need to do is update the package index and run the command sudo apt update. It will refresh the apt cache on your system.

To install Python 3.12, we need to add the dead snakes PPA. Run the following command:


sudo add-apt-repository ppa:deadsnakes/ppa
 

You will see information about PPA on your screen. PPA contains more recent versions of Python packaged for Ubuntu. 
 

 PPA contains more recent versions of Python packaged for Ubuntu

Hit enter to add the repository in the sources list directory. To confirm the repository has been added, run the following command with the path to the sources list directory. 


Ls -l /etc/apt/ sources.list.d/


Here, you can see we have deadsnakes sources list already added. 

deadsnakes sources list already added

Now, the next step is to update the system or the sources list or package list. To do so, run the following command that updates the local package index. 


sudo apt update

 

You can see the repository index here. 
Run the following command and install Python 3.12:
 

sudo apt install python3.12 -y


The given command installs Python 3.12 (along with other additional packages and dependencies). 

The given command installs Python 3.12 (along with other additional packages and dependencies).

Our next task will be to manage the two Python versions that are now installed: 3.12 (the recently installed version) and 3.10.12 (the older version). We must make Python 3.12 our default version to use it. Python versions will be given priorities to accomplish this.

Execute the following command to give an older version of Python a lower priority:


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

Note:

  • usr/bin/python3 shows the path to the Python directory.
  • usr/bin/python3.10 shows the path to the installation directory.
  • 1 represents its priority.

path to the Python directory.

Now, specify Python 3.12 with the same command but assign it a higher priority of 2, hitting enter.
 

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

specify Python 3.12 with the same command

Now, switch between Python versions using the command:

sudo update-alternatives --config python3
 

Python versions using the command
 

It will list the existing versions of Python. In the first row, you can see the asterisk that marks the current Python version, Python 3.12, which is in auto mode. The remaining versions are in manual mode. Here, we are prompted to enter to keep the current choice. Since our choice is Python 3.12, we are going to hit enter.

Check again the version of Python installed with the command:

python 3- V
 

Python installed with the command

And, it is done!

Conclusion

Ubuntu 24.04 boldly steps into performance engineering and confidential computing to deliver an enterprise-grade innovation platform. It has merged low-latency kernel features into the default kernel, reducing kernel task scheduling delays. The above-mentioned steps successfully demonstrate how to install Python 3.12 on an Ubuntu 24.04 machine, which helps you leverage the most recent enhancements in the Linux kernel. You can utilize this version for your projects with ease now.

You can also check how to install FileZilla FTP Client on Ubuntu 20.04 LTS.
 

Share this blog:

Profile picture for user Muntashah
Muntashah
I am an avid writer who enjoys the world of computer science. My strength lies in delivering tech points in easy-to-understand words.