How to Install Python on Ubuntu 24.04

Install Python on Ubuntu 24.04

Ubuntu 24.04, like many of its predecessors, comes with Python preinstalled, making it a great choice for developers and enthusiasts eager to dive into programming right out of the box. However, you may find the need to install additional Python versions or set up a specific development environment tailored to your needs. Whether you’re a seasoned programmer or a curious beginner, understanding how to install Python on Ubuntu 24.04 ensures you can harness the full power and flexibility of this versatile language. In this article, we’ll guide you through the steps to efficiently install Python and configurations on your Ubuntu system, ensuring a smooth and productive coding experience.

Why Install Python on Ubuntu?

Python is a high-level programming language known for its simplicity and readability, making it perfect for both beginners and experienced developers. With a wide range of libraries and frameworks, Python supports diverse applications such as web development, data analysis, artificial intelligence, and automation. Installing Python on Ubuntu, a reliable and user-friendly Linux distribution, enhances its capabilities, offering a powerful development environment. The combination of Ubuntu’s stability and security with Python’s efficiency provides a seamless experience for tackling various programming tasks. Whether you’re building web applications or exploring data science, having Python on Ubuntu gives you a significant advantage.

Check if Python is already installed

Before we dive into the installation methods, let’s check if Python is already installed on your computer. Fire up your terminal and run:

$python3 --version

If it’s installed, you’ll see a similar output. Otherwise, the output will display a message saying: “Command ‘Python3’ not found”.

Method 1: Installing Python on Ubuntu 24.04 through the System Repositories

Installing Python on Ubuntu through the system repositories is perhaps the most straightforward and efficient method. Ubuntu’s package manager, APT (Advanced Package Tool), allows you to easily install and manage Python versions. To begin, update your package list to ensure you have the latest information on available packages. Open a terminal and run:

$sudo apt update

Once updated, you can install Python by executing:

$sudo apt install python3

This command installs Python 3, the default version available in the repositories. To verify the installation and check the installed version, use:

$python3 --version

This method ensures that Python is correctly integrated with Ubuntu, providing a reliable and consistent environment for your development projects. Note, that you might not always get the latest version. For that you can check the official website and the PPA.

Uninstalling Python from Ubuntu 24.04

Uninstalling Python from Ubuntu can be done easily using the APT package manager. To completely remove Python 3 and its associated packages, you can use the `autoremove` and `purge` options together. Open a terminal and execute the following command:

$sudo apt autoremove python3 --purge -y

This command will not only uninstall Python 3 but also remove any dependencies that are no longer needed, ensuring a clean system. The `–purge` option deletes configuration files, and the `-y` option automatically confirms the removal process. This comprehensive approach helps maintain system cleanliness and frees up space by eliminating unnecessary files. But before you remove the default installation, make sure to read the following.

IMPORTANT NOTICE

Removing the out-of-box Python installation from your Ubuntu 24.04 system can lead to severe consequences. as it is a critical component of the operating system. Many essential system functions and applications rely on Python. Removing it can break these dependencies, causing the system to become unusable. Python is deeply integrated into Ubuntu, and numerous system tools depend on it for their functionality.

Attempting to remove Python can result in the removal of many dependent packages, potentially leading to system crashes or rendering the system inoperable. In such cases, the system may only boot into a terminal, requiring complex fixes like reinstalling the desktop environment or other critical components.

In essence, removing the default Python installation from Ubuntu 24.04 is highly discouraged. It can cause significant system instability and potential data loss. Exercise caution when dealing with such critical system components to avoid rendering your system unusable.

Method 2: Installing Python on Ubuntu 24.04 through the PPA

To install Python using a third-party PPA repository on Ubuntu 24.04, follow these steps. Fire up your terminal and add the Deadsnakes PPA to your systems repository list:

$sudo add-apt-repository ppa:deadsnakes/ppa

This command adds the Deadsnakes PPA to your system’s sources list, allowing you to install newer Python versions. Now, update the package lists:

$sudo apt update

This command updates the package lists from the newly added PPA. Now, install the desired Python version. Let’s say you want to install version 3.10. You can install it using:

$sudo apt install python3.10

You can replace `3.10` with the any desired Python version number. After the installation, you can verify it using:

$python3.10 --version

This command should display the installed Python version.

Uninstalling Python and Removing the Third-Party PPA

To remove the third-party PPA and revert to the default Python version, you need to follow these steps. You need to fire up your terminal and first off remove the Deadsnakes PPA from your system’s sources list:

$sudo add-apt-repository --remove ppa:deadsnakes/ppa

If you don’t see any errors, you will have removed the PPA from your computer. Now you need to update the package lists:

$sudo apt update

This command updates the package lists, reflecting the removal of the PPA. After this, now let’s uninstall the Python version installed from the PPA. As we installed version 3.10, we can remove it as such:

$sudo apt remove python3.10

If you installed any other version, you will need to replace `3.10` with the version number you had installed. There you go, you have removed Python from your computer that you installed through the PPA.

Conclusion

In conclusion, installing Python on Ubuntu 24.04 is a straightforward process that can be accomplished using various methods to suit your specific needs. By default, you can leverage the system repositories for a quick and reliable installation, ensuring compatibility and ease of maintenance. For those requiring the latest Python features, adding a Personal Package Archive (PPA) provides access to newer versions and updates. Whether you choose the default repositories for stability or the PPA for cutting-edge developments, Ubuntu 24.04 offers the flexibility to manage your Python environment effectively. By following these methods, you can set up a robust Python development environment tailored to your preferences and project requirements.

For more information on Python, you can check the documentation on the official website. Keep visiting Linux World.