Install Python 3.12 on Ubuntu 22 Linux

Created: Thu 22 Feb 2024 Updated: 4 months ago

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
Server Administrator

POST CATEGORY
  1. Linux
  2. Programming
  3. Cloud
Suggested Posts:
LINUX post image
Understand SELinux module and manage security policies in Linux

This article is all about SELinux. It's a security component that protects Linux systems from …

LINUX post image
Block level full disk cloning using dd in Linux

Taking a backup of a system is very sensitive and critical process and sometimes …

LINUX post image
Setup a local DNS Server

In this article, you'll learn about how you can create and configure a DNS …

CLOUD post image
Migrate EC2 machine from one AWS account to another

Migrating a running EC2 machine from one AWS account to another seems a complicated task. …

KNOWLEDGE post image
Read Binary Bits with these effective methods

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

Sign up or Login to post comment.

Sign up Login

Comments (0)