How To Install Python 2 on Ubuntu 24.04 LTS
In this tutorial, we will show you how to install Python 2 on Ubuntu 24.04 LTS. Python 2, a legacy version of the popular programming language, has played a significant role in the development of countless applications and scripts. Despite the release of Python 3 and its widespread adoption, some users still require Python 2 to maintain compatibility with older codebases or running specific legacy applications.
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 Python 2 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 2 on Ubuntu 24.04
Step 1. Preparing Your System.
To ensure a smooth installation process and maintain system stability and security, it is crucial to update your Ubuntu 24.04 system before installing Python 2. Open a terminal and execute the following commands:
sudo apt update sudo apt upgrade
These commands will refresh the package lists and upgrade any outdated packages to their latest versions. This step helps prevent potential compatibility issues and ensures that you have access to the most recent bug fixes and security patches.
Step 2. Installing Required Dependencies.
Python 2 relies on several system-level dependencies for its installation and functionality. To install these dependencies, run the following command in your terminal:
sudo apt install -y build-essential checkinstall libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev
Step 3. Installing Python 2 on Ubuntu 24.04.
To install Python 2 on Ubuntu 24.04, you need to download the source code. As of writing this article, the latest version of Python 2 is 2.7.18. Use the following command to download the source code tarball:
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
Once the download is complete, extract the tarball using the following command:
tar -xvf Python-2.7.18.tgz
Navigate to the extracted directory using the following command:
cd Python-2.7.18
Now, you can configure, compile, and install Python 2 using the following commands:
./configure --enable-optimizations make sudo make install
After the installation is complete, you can verify that Python 2 is installed correctly by running the following command:
python2 --version
If the installation was successful, you should see output similar to the following:
Python 2.7.18
If you encounter any issues or the command fails to execute, double-check that you have followed all the steps correctly and that there were no errors during the installation process. Common issues include missing dependencies, insufficient permissions, or conflicts with existing Python installations.
Step 4. Installing pip for Python 2.
pip is the standard package manager for Python, allowing you to easily install and manage third-party libraries and tools. To install pip for Python 2, use the following commands:
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py python2 get-pip.py
These commands download the pip installation script and execute it using Python 2. After the installation is complete, you can use pip to install Python 2 packages by running commands like:
pip2 install package_name
Congratulations! You have successfully installed Python. Thanks for using this tutorial for installing Python 2 programming language on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Python website.