Categories: UbuntuUbuntu Feed

How to Install Python 3.12 on Ubuntu 22.04 / 20.04

Python, a versatile and widely used programming language, is essential for a variety of applications, from web development to data science. With the release of Python 3.12, many developers are eager to upgrade or install it on their systems. This article provides a detailed, step-by-step guide to installing Python 3.12 on Ubuntu 22.04 and 20.04.

Prerequisites

Before you begin, ensure you have:

  • A running Ubuntu 22.04 or 20.04 system
  • User account with sudo (admin) privileges

Step 1: Update Your Package List

It’s always a good practice to start by updating your package to ensure you’re installing the latest versions of software packages. Open a terminal and run the following command:

Sponsored
class="terminal"> sudo apt update sudo apt upgrade

Enter your password when prompted.

Step 2: Install Essential Dependencies

Python 3.12 requires some essential build tools and libraries. You can install them by running the following command:

sudo apt install -y software-properties-common build-essential libffi-dev libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev libffi-dev libssl-dev 

This command will install the necessary dependencies for Python compilation and other libraries required for Python to function properly.

Step 3: Add DeadSnakes PPA

Python 3.12 is not available in the default Ubuntu repositories. To get the latest Python versions, you can use the “DeadSnakes” Personal Package Archive (PPA). Add the PPA to your system by running the following command:

sudo add-apt-repository ppa:deadsnakes/ppa 

You will be prompted to press Enter to continue. Do so to add the PPA to your system.

Step 4: Install Python 3.12

After adding the PPA, update the package list once more to include the new repository:

sudo apt update 

Now that you have added the DeadSnakes PPA and updated your package list, you can install Python 3.12 using the following command:

sudo apt install -y python3.12 python3.12-venv  

This command will install Python 3.12 and all its related packages.

Step 5: Verify the Installation

Check the installed Python version:

Sponsored
python3.12 --version 

You should see the Python version displayed in the terminal, confirming that Python 3.12 is installed on your system.

Step 6: Set Python 3.12 as the Default (Optional)

If you want to make Python 3.12 your default Python version, you can use the update-alternatives command. However, be cautious when changing the default Python version, as it may affect system scripts and applications. To set Python 3.12 as the default, run the following commands:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 312 
sudo update-alternatives --config python3 

Select the number corresponding to Python 3.12 from the list, and press Enter.

Once changes done, you can verify the change with python --version.

Step 7: Install Pip for Python 3.12

Pip is a package manager for Python. Install it by running:

sudo apt install python3.12-distutils 
wget https://bootstrap.pypa.io/get-pip.py 
sudo python3.12 get-pip.py 

Check the Pip version with pip3 --version.

Step 8: Clean Up (Optional)

After the installation, you may clean up unnecessary packages:

sudo apt autoremove 

Conclusion

You’ve successfully installed Python 3.12 on your Ubuntu 22.04 or 20.04 system. This setup opens a pathway to explore the latest features and improvements of Python 3.12. Whether for development, data analysis, or scripting, you’re now ready to take advantage of Python’s powerful capabilities on your Ubuntu machine.

Remember to stay updated with Python and Ubuntu releases for a smooth programming experience.

The post How to Install Python 3.12 on Ubuntu 22.04 / 20.04 appeared first on TecAdmin.

Ubuntu Server Admin

Recent Posts

Canonical Releases Ubuntu 25.04 Plucky Puffin

The latest interim release of Ubuntu introduces “devpacks” for popular frameworks like Spring, along with…

2 days ago

Ubuntu 25.04 (Plucky Puffin) Released

Ubuntu 25.04, codenamed “Plucky Puffin”, is here. This release continues Ubuntu’s proud tradition of integrating…

3 days ago

Extended Security Maintenance for Ubuntu 20.04 (Focal Fossa) begins May 29, 2025

Ubuntu released its 20.04 (Focal Fossa) release 5 years ago, on March 23, 2020. As…

3 days ago

Ubuntu 20.04 LTS End Of Life – activate ESM to keep your fleet of devices secure and operational

Focal Fossa will reach the End of Standard Support in May 2025, also known as…

4 days ago

Ubuntu MATE 25.04 Release Notes

Ubuntu MATE 25.04 is ready to soar! 🪽 Celebrating our 10th anniversary as an official…

5 days ago

Ubuntu Weekly Newsletter Issue 887

Welcome to the Ubuntu Weekly Newsletter, Issue 887 for the week of April 6 –…

6 days ago