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: 9 months ago

POST CATEGORY
  1. Linux
  2. Programming
  3. Cloud
Suggested Posts:
LINUX post image
Django Checklist for Deploying Application in Production

While experience in the development and production environment of django application is almost similar, …

KNOWLEDGE post image
Read Binary Bits with these effective methods

You are most likely familiar with the concept of Binary Language. Yes, you guessed …

LINUX post image
Setup a new project on git and learn useful git commands

Git has become an essential tool for modern software development, enabling developers to collaborate, track …

PROGRAMMING post image
Basic Python Coding Questions and Answers

Python is one of the most powerfull programming language. Python is used in web-development, …

LINUX post image
Get Free valid SSL Certificate from Trusted CA

SSL plays a key role when it comes to your website security and encrypted …

Sign up or Login to post comment.

Comments (0)