Website Vidya
DevelopmentStep-by-Step Guide

How to Install Python on Ubuntu 24.04 LTS

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 w...

RR
Website Vidya TeamLead Systems Educator
Published:
6 min read
How to Install Python on Ubuntu 24.04 LTS
AI Executive SummaryCORE CIS AI

6 min read

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 w...

Key Highlights
  • Prerequisites
  • How to Install Python and Pip on Ubuntu
  • Troubleshooting Tips
Grounded in full engineering runbookCORE CIS Ai Engine

Python is one of the most popular, versatile, and widely-used programming languages today, underpinning everything from web development and automation to data science and artificial intelligence. Pip is Python’s official package manager, allowing you to install, update, and manage third-party Python software packages easily.

Ubuntu 24.04 LTS, being a modern and stable Linux distribution, comes equipped with Python pre-installed, but sometimes you may want to install a specific Python version or set up pip to start managing Python libraries effectively.

This guide will take you through the process of installing both Python and pip on Ubuntu 24.04 LTS, step-by-step, including tips on verifying the installation and managing Python environments.


Prerequisites

Before starting the installation:

  • You need a running Ubuntu 24.04 LTS system (local machine or VPS).
  • Ensure you have a user account with sudo privileges.
  • You should have access to a terminal or SSH client.
  • A stable internet connection for downloading packages.

How to Install Python and Pip on Ubuntu


Step 1: Check Existing Python Installation

Ubuntu 24.04 LTS usually ships with Python 3.12 pre-installed. To confirm this, open your terminal and run:

python3 --version

You should see output like:

Python 3.12.3

If Python 3 is installed, you can proceed to set up pip. If Python is not installed or you want a different version, follow the next step to install or update Python.cherryservers+2


Step 2: Install or Update Python on Ubuntu 24.04 LTS

Even though Python is generally pre-installed, you might want to ensure you have the latest patched version or install multiple Python versions side by side.

Basic Python 3 Installation

Update your package list:

sudo apt update

Then install Python 3:

sudo apt install python3 -y

Verify the installation:

python3 --version

Installing Specific Python Versions

If you want a specific version like Python 3.10, Ubuntu supports installing it from the deadsnakes PPA:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.10

Switch between them by invoking python3.10 directly or configuring alternatives.vultr


Step 3: Install Pip for Python 3

Pip simplifies installing and managing additional Python packages. To install pip on Ubuntu 24.04:

sudo apt install python3-pip -y

This command installs pip and its dependencies.

Check the pip version installed:

pip3 --version

Example output:

pip 24.0 from /usr/lib/python3/dist-packages/pip (python 3.12)

Step 4: Managing Pip and Python Packages

With pip installed, you can now install any Python package available on the Python Package Index (PyPI). For example:

pip3 install requests

To upgrade pip itself:

pip3 install --upgrade pip

Remember to use pip3 explicitly, as pip may point to Python 2's package manager if installed.


Step 5: Using Virtual Environments (Optional but Recommended)

To keep project dependencies isolated and avoid conflicts, use Python virtual environments.

Install the virtual environment package:

sudo apt install python3-venv -y

Create a new virtual environment:

python3 -m venv myenv

Activate it:

source myenv/bin/activate

Once activated, pip3 install commands install packages only within this environment, keeping your global Python setup clean.

To exit the environment, use:

deactivate

Step 6: Alternative – Installing Python 2.7 & Pip (Legacy Use)

Ubuntu 24.04 LTS does not include Python 2.7 by default since it's end-of-life. If required for legacy applications, you must compile it from source:

  • Update system and install dependencies
  • Download Python 2.7.18 source tarball and compile manually

Because of its complexity and obsolescence, it's better to migrate to Python 3, but the process is available online if needed.github


Troubleshooting Tips

  • command not found errors: Ensure you installed packages with sudo, and that the binaries like python3 and pip3 are on your PATH.
  • Permission issues with pip: Use virtual environments or run pip with --user for local installs.
  • Mismatch of Python and pip versions: Always use python3 and pip3 explicitly to avoid version conflicts.
  • Update package lists: Always run sudo apt update before installing new software.

Summary

To recap, here’s the concise sequence:

  1. Check existing Python version: python3 --version
  2. Update packages: sudo apt update
  3. Install Python 3 (if needed): sudo apt install python3
  4. Install pip for Python 3: sudo apt install python3-pip
  5. Verify pip: pip3 --version
  6. (Optional) Use virtual environments for isolated package management.

This approach will get your Ubuntu 24.04 LTS system fully equipped for Python development swiftly and reliably.


Why This Matters

Python and pip form the foundation for an immense ecosystem of tools and frameworks in today’s technology landscape—from web frameworks like Django and Flask, data science libraries like Pandas and NumPy, to machine learning and automation scripts. Ubuntu’s ease of use and large community support make it an ideal platform for Python development, and mastering how to install and configure these tools correctly is key to being productive and avoiding dependency conflicts.

Start your journey with this guide, and soon you’ll be ready to build, automate, analyze, and explore almost any Python application on your Ubuntu 24.04 LTS system.


Written by

Website Vidya Team

Technology educator and researcher at Website Vidya.

Discussion

0
Share your thoughts, ask a question, or suggest a tip...
Write →

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides