How to Install Python 3.12 in Ubuntu
Let’s take a closer look at how you can install Python on Ubuntu, with a brief guide on updating the Python package as well.
How to Install Python 3.12 on Ubuntu
Installing Python on Ubuntu is easy. You can get the latest version of Python from multiple sources. Here are some of the recommended ways:
1. Install Python 3 on Ubuntu using APT
APT, or Advanced Package Tool is the default package manager on Ubuntu and other Debian-based distros. You can download the Python package from the official Ubuntu repository. Here’s how to do it:
sudo apt install software-properties-common
# Add the official Deadsnakes PPA to your system's repository
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
# Download the latest version of Python from the added PPA
sudo apt install python3.12
3. Install Python 3 on Ubuntu From Source
You can also download and build the latest version of Python from the official Python website. Although compiling the source code might seem a bit daunting at first, it’ll become easier once you know the process.
sudo apt update
# dependencies
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
# Make a new directory to store the Python source files
mkdir ./python && cd ./python
# Download the Python source code
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0b3.tgz
# Extract the TGZ file
tar -xvf Python-3.12.0b3.tgz
cd Python-3.12.0b3
./configure --enable-optimizations
# build
sudo make install
# check
python3.12 - version
Install PIP
python3.12 get-pip.py
Ambiente Virtual Python
python3.12 -m pip install virtualenv
python3.12 -m virtualenv ~/envs/my-env/
source ~/envs/my-env/bin/activate
python --version
Updating Python to the Latest Version
You can also use the — only-upgrade flag with the command:
sudo apt --only-upgrade install python3