UbuntuUbuntu Based

How To Install Python on Ubuntu 24.04 LTS

Install Python on Ubuntu 24.04

In this tutorial, we will show you how to install Python on Ubuntu 24.04 LTS. Python is a versatile and powerful programming language that has gained immense popularity among developers worldwide. Its simplicity, readability, and extensive library support make it an ideal choice for a wide range of applications, from web development to data analysis and machine learning.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Python programming language on Ubuntu 24.04 (Noble Numbat). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
  • An Ubuntu 24.04 system with root access or a user with sudo privileges.

Install Python on Ubuntu 24.04 LTS Noble Numbat

Step 1. Updating the Package Repository.

Before we dive into the installation process, let’s ensure that your Ubuntu 24.04 system is up to date. Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade

These commands will update the package list and upgrade any existing packages to their latest versions.

Step 2. Installing Python on Ubuntu 24.04.

  • Method 1: Installing Python Using Default Package Manager (APT)

The simplest way to install Python on Ubuntu 24.04 is by using the default package manager, APT (Advanced Package Tool). Follow these steps to install Python using APT:

sudo apt install python3

After the installation is complete, you can verify the installed Python version by running:

python3 --version

You should see the Python version number displayed in the output.

  • Method 2: Installing Python Using Deadsnakes PPA

While the default package manager provides a stable version of Python, you may require a specific version for your projects. The Deadsnakes PPA (Personal Package Archive) is a popular third-party repository that offers a wide range of Python versions for Ubuntu. Follow these steps to install Python using the Deadsnakes PPA:

sudo add-apt-repository ppa:deadsnakes/ppa

To install a specific version of Python, use the following command syntax:

sudo apt update
sudo apt install python3.x

Replace x with the desired Python version. For example, to install Python 3.12, run:

sudo apt install python3.12

Once the installation is complete, you can verify the installed Python version by running:

python3.12 --version
  • Method 3: Installing Python from Source Code

If you need even more control over the Python installation or want to install a version that is not available through the package manager or PPA, you can compile and install Python from the source code. Follow these steps:

To compile Python from source, you need to install the necessary build dependencies. Run the following command:

sudo apt install build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev

Visit the official Python download page and copy the URL of the desired Python version’s source code tarball (e.g., Python-3.12.3.tgz):

wget https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tgz

Extract the downloaded tarball using the following command:

tar -xvf Python-3.12.3.tgz

Navigate to the extracted directory:

cd Python-3.12.3

Configure the Python build by running:

./configure --enable-optimizations

Compile Python using:

make

Finally, install Python by running:

sudo make install

After the installation is complete, you can verify the installed Python version by running:

python3.12 --version

Step 3. Installing pip for Python 3.

pip is the package installer for Python, allowing you to install and manage additional libraries and dependencies. To install pip for Python 3, run the following command:

sudo apt install python3-pip

You can verify the pip installation by running:

pip3 --version

Step 4. Setting Up a Virtual Environment.

Virtual environments are isolated Python environments that allow you to manage dependencies separately for each project. To create a virtual environment, first install the virtualenv package:

sudo apt install virtualenv

Then, navigate to your project directory and create a new virtual environment:

virtualenv myenv

Activate the virtual environment by running:

source myenv/bin/activate

You can now install packages specific to your project within this virtual environment using pip.

Congratulations! You have successfully installed Python. Thanks for using this tutorial for installing the Python programming language on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the Python website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button