Install Python 3.12 on Ubuntu 22 Linux

article-featured-image

Choosing the right Python version for your Python application plays an important role in future-proofing the application. In this article, we'll look into two methods to install Python 3.12 on Linux systems. Ubuntu server 22.04 LTS comes with Python version 3.10.12 by default. To install Python version 3.12 on Ubuntu 22.04 system, use the following methods:

Using PPA repository

This is the easiest way to install the required Python version in Ubuntu 22.04 LTS. But first, you need to install the required system package for adding a new repository. Use the below command:

$
sudo apt install software-properties-common

After installing the above package in the system, you can now add PPA repository. We'll use deadsnakes PPA repository that contains the latest and old Python versions for Ubuntu. Keep in mind that PPA's are third-party repositories that are managed by individuals or groups outside of the official Ubuntu package maintainers.

To add deadsnakes repository, use below command:
$
sudo add-apt-repository ppa:deadsnakes/ppa

$
sudo apt update
Repository is now added and you can install Python version 3.12 using:
$
sudo apt install python3.12

Build from source package

If you don't want to use third-party PPA repositories, then you have the compile the required Python version yourself from the source. However, the process is pretty straight-forward if you have all the reuqired packages installed in your Ubuntu system.

Use below command to install system packages that are necessary to compile Python version from source:
$
sudo apt -y install build-essential pkg-config wget libssl-dev zlib1g-dev libncurses5-dev libgdbm-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev libnss3-dev libdb-dev liblzma-dev tk-dev uuid-dev

Installing system packages might take some time (depends upon your internet speed and disk type). Now download Python version 3.12 source file from Python official archive or use the below command to download directly in your current directory:

$
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tar.xz

$
tar xvf Python-3.12.0.tar.xz

After downloading the source package and extracting it, move to the Python-3.12.0 directory and use the below commands to compile Python from build:

$
cd Python-3.12.0

$
./configure --enable-optimizations

$
make

$
sudo make altinstall

If you want to install the Python version 3.12 as the default version of your system, then instead of sudo make altinstall, use sudo make install command.

This process might take time (depending on your system hardware). After the process in completed, run python3.12 --version command in your terminal to verify the installation.

Latest Python for Ubuntu 22
protocolten-admin

Author: Harpreet Singh

Created: Thu 22 Feb 2024

Updated: 10 months ago

POST CATEGORY
  1. Linux
  2. Programming
  3. Cloud
Suggested Posts:
LINUX post image
Configure Django with Apache, MySQL and WSGi on Ubuntu

In this article, I'll be demonstrating how we can deploy Django website on an …

LINUX post image
Define and use environment variables in Linux & Python

This article is about Environment variablesand their uses in Linux and Python as well. …

LINUX post image
Containerization with docker

Containerization is a way of packaging an application along with all of Its required libraries, …

LINUX post image
Create desktop entry of application on Linux

In this article, I'll show you how you can create desktop entrie for application …

WINDOWS post image
Create environment variables and paths in windows

Windows environment variables and paths are essential components of the operating system, acting as pointers …

Sign up or Login to post comment.

Comments (0)