How to Install Python 3.12 on Ubuntu 24.04: The Complete Guide

Ubuntu 24.04 just got released, and with it comes the excitement of installing the latest Python version, Python 3.12! For Linux enthusiasts and freedom fighters who value open-source tools, Python 3.12 brings new features, bug fixes, and performance improvements. Whether you’re a beginner or an experienced developer, installing Python 3.12 on Ubuntu is a great way to stay up-to-date. Here’s how you can do it in multiple ways, from easy package installations to manual builds from source.

Methods for Installing Python 3.12 on Ubuntu 24.04

  1. Install Python 3.12 Using APT (If Available)
    Ubuntu’s APT package manager is the simplest and fastest way to install Python if the latest version is already in its repository.
   sudo apt update
   sudo apt install python3.12

Run python3.12 --version to confirm it’s installed. If you see Python 3.12.x, then you’re all set! If not, keep reading for more ways to get it installed.

  1. Install Python 3.12 from the deadsnakes PPA
    For users needing the latest Python on older repositories, the deadsnakes PPA is a popular option. Here’s how:
   sudo apt update
   sudo apt install software-properties-common
   sudo add-apt-repository ppa:deadsnakes/ppa
   sudo apt update
   sudo apt install python3.12

Now, check with python3.12 --version to confirm installation.

Install Python 3.12 from Source Code

This is for those who want complete control over their Python build. Downloading from source allows you to customize features. Here’s how:

Install dependencies:

sudo apt update
sudo apt install -y build-essential libssl-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev

Download Python 3.12 source:

cd /tmp
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz

Extract and compile:

tar -xf Python-3.12.0.tgz
cd Python-3.12.0
./configure --enable-optimizations
make -j $(nproc)
sudo make altinstall

Verify:
Run python3.12 --version. This should show Python 3.12.x, confirming the source build was successful.

Install Python 3.12 Using pyenv

pyenv is a tool that lets you switch between multiple Python versions without altering system-wide settings. Here’s how:

curl https://pyenv.run | bash

Add pyenv to your shell by following the instructions printed on the screen. Then, install Python 3.12 with:

pyenv install 3.12.0
pyenv global 3.12.0

Confirm by running:

python --version

You should see Python 3.12.x as the output.

Bonus Tip: Virtual Environments

Using virtual environments for each project helps avoid conflicts. Set up a virtual environment with Python 3.12 like this:

python3.12 -m venv venv
source venv/bin/activate
# You can do this too
. ./venv/bin/activate

This keeps dependencies clean and project-specific.

Conclusion

And that’s it! You’ve installed Python 3.12 on Ubuntu 24.04. Whether you went with APT, deadsnakes, building from source, or pyenv, you’re ready to explore Python’s newest features. Happy coding, and let’s keep supporting Free and Open Source Software!

You Might Also Like

Leave a Reply