Sal
akash "Akash Blog". min read

How to Install Python 3.12 on Ubuntu 22.04

Python3.12

Python is a high-level, interpreted programming language known for its simplicity, readability, and versatility.

Python 3.12 is the latest stable release of the Python programming language. This tutorial illustrates two methods of how to install it on your Ubuntu 22.04 OS.

  • Install Python 3.12 from the deadsnakes PPA

Update Operating System

Update your Ubuntu 22.04 operating system to the latest version with the following command:

sudo apt update

Method 1: Install Python 3.12 with APT

Installing Python 3.12 on Ubuntu 22.04 using APT is quite easy, a big thumbs up to the deadsnakes custom PPA!

This makes it easy to install Python on Ubuntu and be able to receive continued updates, bug fixes, and security updates.

Install the prerequisite for adding custom PPAs:

sudo apt install software-properties-common -y

Then proceed and add the deadsnakes PPA to the APT package manager sources list:

sudo add-apt-repository ppa:deadsnakes/ppa

Press Enter to continue.

Once the repository has been installed, run an APT update to ensure that the newly imported PPA is reflected.

sudo apt update

You can now install Python 3.12 with the following command:

sudo apt install python3.12

To verify the installation and Python 3.12 build version, perform the following:

python3.12 --version 3.12.0

If you have installed Python 3.12 using the APT package manager, the PIP will not be installed by default. To install PIP, run the following command:

curl -sS https://bootstrap.pypa.io/get-pip.py | python3.12

If curl command is not found Then install curl : sudo apt install curl

You can check PIP for the Python 3.12 version using the following command:

# pip3.12 -V pip 23.2.1 from /usr/local/lib/python3.12/site-packages/pip (python 3.12)

Setting up a virtual environment

A virtual development environment on a production server is considered a great solution compared to running in a main development environment. In a virtual environment, you can edit and not damage the files of the main development environment. We can create as many virtual environments as we need. Each virtual environment is deployed in different directories on our server. The directories contain files for initializing the virtual environment.The virtual environment is deployed using the installed venv (virtual environment) package

sudo apt install python3.12-venv

Create new virtual environment

python3.12 -m venv env_test
  Never miss a story from us, get weekly updates in your inbox.