Summary
Every year, the Python programming language receives major updates and improvements. But the version preinstalled on Ubuntu Linux may not be the latest. If you need a more up-to-date release, here are the steps to getting the latest version of Python on Ubuntu.
For this tutorial, we’re using the Ubuntu 22.04 LTS version. For demonstration, we will install Python 3.12, which was released on Jun 29, 2025. But this guide is applicable for older versions of Ubuntu and any upcoming Python releases.
Step 1: Check If Python Is Installed (And the Current Version)
Python comes installed on Ubuntu by default. Just to be sure, you can ensure it’s installed bychecking its current version. That also shows you which version is installed and whether it’s already in its latest version or not.
To check your Python version on Ubuntu, run the below command:
As you can see in our case, it’s 3.10.12, which is not the latest version. To compare your results, you’ll find all the version numbers and maintenance statuseson the official Python website.
With that out of the way, let’s proceed to install the latest version of Python on our Ubuntu device.
Step 2: Install the Latest Python Version on Ubuntu
We’ll cover two methods here. If you want a quick and simple method, go with the first one. If you’re more comfortable building software from source files, use the second method.
Method 1: Install the Latest Version of Python Using deadsnakes PPA
A Personal Package Archive (PPA) is a third-party repository that contains software packages. You need to add such repositories to your repo list first. Then you’ll be able to install any software from that repository. For the latest version of Python, we’re going to usedeadsnakes PPA. It contains many versions of Python. To add that repository, use the below command:
When asked to confirm, press the Enter button.
To make the changes take effect, you need to update your software repository cache. So update it with this command:
Now you’re ready toinstall software from the PPA. So install the latest version of Python by simply inputting this command:
Press “y” followed by the Enter button to start the installation. Wait until the installation is finished. After the installation, you’re able to start using the new version right away. For that, you need to use the version number when choosing Python. So in this example, we’re going to use this command:
Instead, if you want to use the new version as the default one, then proceed to step 3.
Method 2: Install the Latest Version of Python Using the Source Code
Another method for manually installing Python is using the source file fromthe official Python website.
Before going into the process, you’ll need some packages installed that are essential for building software from the source. First, update your system with the below command:
Now you’re ready to install Python using the source file.
So now, go tothe downloads page. Then press the “Download Python ” button to start the download.
Open your terminal and navigate to the location where you downloaded the file. By default, it’s the “Downloads” directory. Go to that directory with this command:
The source file is an XZ compressed source tarball file. You need toextract this tar file first. Extract the Python source file with this command:
Depending on which version you downloaded, your file name will be different and so will the command. Navigate into the created directory with this command:
Now you need to compile the Python source code. For that, we’ll use the provided “configure” script. Compile the source code by running the below command:
We’ve also added the –enable-optimizations option to the script to enable various compile-time optimizations so that Python runs faster. The script will create the necessary Makefiles for us. Use the generated Makefile to build Python with this command:
This will take a while so wait patiently. If you’ve successfully executed all the commands, that should install the latest Python on your Ubuntu system.
Once the process is done, you should have the installed version as the default one on your device. To see that, check the Python version again:
Our system is now using Python 3.12, as expected.
(Optional) Step 3: Change Your Default Python Version
You should’ve successfully installed the latest version of Python by now. However, if you used the PPA method, that’s not enough to start using the new version of Python by default. Your system is still using the old version. you’re able to verify that by checking the version again.
To make sure you’re using the installed version, you must change the symbolic link to point to that version. You can do that using the update-alternatives command. Let us show you how.
We will specify the path to the newly installed Python for the python3 command we use. To do that, run the below command:
Again, depending on the version you install, the command will slightly differ because of the version number. The “1” at the end of the command specifies the priority you want to put the version in. This saves you from any conflict because the higher the priority number, the higher the precedence.
If there is only one alternative in the link group, then this should be enough to make the new version the default one. But, if there are several versions in the group, you need to select the new version. For that, run the below command:
Notice the numbers under the “Selection” column. Enter the order number for the Python version you want to use. Then press the Enter button. Now you should be using the latest Python version on Ubuntu. Check the version to confirm one last time.
Should You Upgrade to a New Version of Python?
New versions of programming languages such as Python always come with perks such as improved performance, security patches, more usability, and better system support, among others. So it might seem logical to update to the latest version. And in general, that’s totally fine.
But it does come with some catches. Upgrading to a new version can change the way you use the language if there is a big change in a part of the syntax. So you’ll need some getting used to before it becomes normal again. Some packages may not support the new version right away. Even worse, some new versions can break your existing projects and make a mess. So you must be careful with that.
If the new Python version contains a useful feature you want to use or has important security updates and bug fixes, then feel free to upgrade to that version, providing that it’s compatible with your old code. So, it comes down to your needs and preferences.
Our recommendation would be to use the new Python version in a separate environment to test how it works before you start implementing it on a major project. You can also usepyenvto switch between versions when working on different tasks.
Gear Up With the New Python Version
With the latest version of Python installed on your Ubuntu device, you may start taking advantage of all the new features available. Remember to read therelease notesand theofficial documentationto learn more about that version.
Interested in installing Python on platforms other than Ubuntu? Check out our comprehensive guide onhow to install Python on Windows.