31.03.2026

How to Install Python 3 on Ubuntu 24.04

Although modern Linux distributions provide graphical interfaces, software installation and management are significantly faster and more flexible via the command line. Python, a versatile programming language, can be installed on Ubuntu 24.04 in multiple ways depending on your needs.

Check if Python is already installed
Open the terminal and run:

python3 --version

If Python is installed, it will return a version like Python 3.12.x. If not, proceed with installation.

Option 1: Install via apt (default Ubuntu repository)
Update the system first:

sudo apt update && sudo apt upgrade -y

Install Python 3 and essential development tools:

sudo apt install python3 python3-pip python3-venv python3-dev -y

Check the installation:

python3 --version
pip3 --version

This method is simple but may not provide the latest Python version.

Option 2: Install a specific version using deadsnakes PPA
For newer Python versions:

sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.11 python3.11-venv python3.11-dev -y

Run the new version:

python3.11 --version

This is ideal if you need a specific Python version for compatibility.

Option 3: Install via pyenv (manage multiple Python versions)
Pyenv allows easy switching between Python versions. Install dependencies:

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

Install pyenv:

curl https://pyenv.run | bash

Add pyenv to your shell (~/.bashrc or ~/.zshrc):

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"

Install a Python version:

pyenv install 3.12.1
pyenv global 3.12.1

Verify:

python --version

Pyenv is perfect for developers working on multiple projects with different Python versions.

Option 4: Build Python from source
For maximum control over features and optimizations:

sudo apt install build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libffi-dev libbz2-dev wget -y
wget https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tgz
tar -xf Python-3.12.1.tgz
cd Python-3.12.1
./configure --enable-optimizations
make -j$(nproc)
sudo make altinstall

Use python3.12 to run it without replacing the system default Python.

Virtual environments
To isolate project dependencies:

python3 -m venv myenv
source myenv/bin/activate
pip install requests
deactivate

Cheat Sheet

Conclusion
Python 3 can be installed on Ubuntu 24.04 in multiple ways: via apt for simplicity, deadsnakes PPA for specific versions, pyenv for version management, or from source for maximum customization. Using virtual environments ensures isolated dependencies for smooth development.