Python is one of the most popular programming languages today, widely used in web development, data science, machine learning, automation, and more. Ubuntu 24.04 LTS (Long Term Support) comes with Python pre-installed, but often you might want to install a specific Python version, upgrade to the latest release, or configure your system for Python development environments.
This article will guide you step-by-step on how to install Python on Ubuntu 24.04 LTS using several methods, from the easiest default package installation to building Python from source. It also covers pip installation, creating virtual environments, and managing multiple Python versions for developers.
Prerequisites
Before starting the installation, ensure you have:
- An Ubuntu 24.04 LTS system (local machine or server).
- A non-root user with sudo privileges.
- A stable internet connection to download packages and dependencies.
- Basic knowledge of using the terminal/command line interface.
How to Install Python on Ubuntu 24.04 LTS
Step 1: Update Your System
It’s always recommended to start by updating your system packages to their latest versions to avoid issues during installation. Open your terminal and run:
sudo apt update -y && sudo apt upgrade -y
This command will update the package list and upgrade existing packages, keeping your system fresh and secure.
Step 2: Check Existing Python Version
Ubuntu 24.04 usually comes with Python 3.12 pre-installed. Verify the installed Python version on your system with:
python3 --version
You should see an output similar to:
Python 3.12.3
If Python is not installed or you want a different version, proceed to the next steps.
Step 3: Install Python Using APT (Default Repository)
The easiest method to install Python on Ubuntu 24.04 is using the APT package manager since Python 3 is included by default in the Ubuntu repositories.
To install Python 3, run:
sudo apt install python3
This will install the default Python 3 version available in the repository (typically the latest stable release like 3.12.x). Verify the installation again with:
python3 --version
Step 4: Install Specific Python Versions Using Deadsnakes PPA
If you want a specific Python version that’s not in the default Ubuntu repo (e.g., Python 3.10, 3.11), you can use the third-party Deadsnakes PPA repository, which hosts multiple Python versions.
Install software-properties-common which allows adding PPAs:
sudo apt install software-properties-common -y
Add the Deadsnakes PPA:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
Install a specific Python version, for example, Python 3.11:
sudo apt install python3.11
Verify the installed version:
python3.11 --version
Step 5: Install Python from Source (Advanced)
Installing Python from source lets you get the absolute latest version or customize the build options.
Install build dependencies:
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev pkg-config wget -y
Download the latest Python source code (replace 3.12.4 with the latest available version):
wget https://www.python.org/ftp/python/3.12.4/Python-3.12.4.tgz
Extract the tarball:
tar -xf Python-3.12.4.tgz
cd Python-3.12.4
Configure the build with optimizations for faster execution:
./configure --enable-optimizations
Compile and install (this may take several minutes):
make -j $(nproc)
sudo make altinstall
The altinstall avoids overwriting the system default Python.
Verify installed Python version:
python3.12 --version
Step 6: Install Pip for Python Package Management
Pip is the official package installer for Python, enabling you to install and manage additional Python libraries easily.
To install pip for the system Python version, run:
sudo apt install python3-pip -y
Check pip version with:
pip3 --version
If you installed a specific Python version via PPA or source and want pip, sometimes manual installation is needed:
sudo apt install python3.12-distutils
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3.12 get-pip.py
Step 7: Setup Python Virtual Environments
Virtual environments let you create isolated Python environments, useful to maintain dependencies per project without conflicts.
Install the virtual environment package for your Python version:
sudo apt install python3-venv
For specific Python versions (e.g., 3.12):
sudo apt install python3.12-venv
Create a virtual environment:
python3 -m venv myenv
Replace myenv with your desired environment name.
Activate the virtual environment:
source myenv/bin/activate
Your terminal prompt will change indicating the environment is active. You can install packages there separately with pip.
To deactivate:
deactivate
Step 8: Managing Multiple Python Versions
When multiple versions are installed, use the full version command (e.g., python3.11) or set the default Python version via the update-alternatives system:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2
sudo update-alternatives --config python3
Choose the desired default Python version interactively.
Step 9: Remove Python Versions (If Needed)
To remove Python installed via APT or PPA:
sudo apt purge python3* -y
For source installations, manually delete the installed folders and symbolic links:
sudo rm -rf /usr/local/lib/python3.12
sudo rm /usr/local/bin/python3.12
Conclusion
Installing Python on Ubuntu 24.04 LTS is straightforward with multiple options catering to various use cases:
- Use APT for quick installation of default Python versions.
- Use Deadsnakes PPA for specific or newer versions.
- Build from source for full control over Python builds.
- Pip and virtual environments empower effective package and project management.
By following these steps, anyone can set up a robust Python environment on Ubuntu 24.04 for development, scripting, or production workloads efficiently.
FAQs: How to Install Python on Ubuntu 24.04 LTS
Is Python pre-installed on Ubuntu 24.04 LTS?
Yes, Ubuntu 24.04 LTS comes with Python 3.12 pre-installed by default. You can verify this by running python3 --version in the terminal.
How do I install Python if it’s not already installed?
You can install Python using the APT package manager with the command sudo apt install python3. This installs the default Python 3 version in the Ubuntu repositories.
How can I install a specific Python version like 3.10 or 3.11 on Ubuntu 24.04?
Use the Deadsnakes PPA repository to install specific Python versions:
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.10
How do I verify the installed Python version?
Run python3 --version or python3.x --version (replace x with the minor version number) to check the installed Python version.
How can I install pip for Python package management?
Run sudo apt install python3-pip to install pip for Python 3 and verify with pip3 --version. For specific Python versions, you might need to install pip manually.
Can I install Python from source on Ubuntu 24.04?
Yes, you can download Python source code from python.org, compile it with ./configure --enable-optimizations, then make and sudo make altinstall for custom installations.
What is the recommended way to manage multiple Python versions on Ubuntu 24.04?
Use the update-alternatives tool to configure and switch between different Python versions installed on your system.
How do I create isolated Python environments?
Use Python’s built-in venv module by running python3 -m venv myenv to create a virtual environment and activate it with source myenv/bin/activate.
How do I remove a Python version installed via APT or PPA?
You can remove installed versions by running sudo apt purge python3* -y. For source installations, manually delete the installed files and symbolic links.
Where can I find help if I encounter issues during installation?
Ubuntu forums, Python community support, and official documentation are great resources for troubleshooting Python installation issues on Ubuntu.

How to Start, Stop, and Restart the Nginx Service in 2025