Ubuntu is an open-source Linux distribution that supports several programming languages such as Python, Java,  C++, etc. Python is a multiple-purpose programming language with enriched features and can be installed easily on Ubuntu. This blog post will demonstrate the complete process of Python installation on Ubuntu 22.04.

How to Install Python on Ubuntu?

Python can be installed on Ubuntu machines using the Official Python Repository, Deadsnakes PPA, and from the Source Code.

Let’s discuss each method with stepwise instructions.

Method 1: Install Python on Ubuntu From the Official Python Repository

To install Python from the official Python repository, follow the steps listed below:

  • Update the Packages.
  • Install Python.
  • Use Python.
  • Verify the Installation.
  • Quit Python Session.

Step 1: Update the Packages

It is recommended to update system packages before installing any new software/package. Use the command given below to update the system.

$ sudo apt update

It can be noticed that the system packages are updated successfully.

Step 2: Install Python

Now use the following command to install Python on Ubuntu 22.04 LTS.

$ sudo apt install python3

In our scenario, it’s already installed 

Step 3: Use Python

To verify Python installation, use the below-listed command:

$ python3

It can be seen that Python3 is installed and working perfectly fine.

Step 4: Verify the Installation

Now check/verify the Python version installed on your Ubuntu machine using the command:

$ python3 --version

In our scenario, it’s 3.10.12

Step 5: Quit Python Session

To end the Python session, execute the following command:

$ quit()

Method 2: Using Deadsnakes PPA

Deadsnakes PPA(Personal Package Archives) allows you to install multiple Python packages on Ubuntu.

It offers packages for various Python versions.

The step-by-step procedure to install Python on Ubuntu using the Deasnakes PPA is given below:

Step1: Manage the Distributions

We first have to manage the distributions. It is required to manage your software packages from independent sources. Use the following command to do so:

$ sudo apt install software-properties-common

Step2: Add Deadsnakes PPA 

Now we have to add deadsnakes PPA to Ubuntu’s repository:

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

Step 3: Update the System

Now update the system using the command given below:

$ sudo apt update

Step 4: Install Python

Now use the command for Python installation.

$ sudo apt install python3

In our scenario, it is already installed so the terminal displays “Python is already to the newest version”.

Method 3: Python Install Using the Source Code

To install Python in Ubuntu from the source code, follow the step-by-step procedure shown below:

Step 1: Update the System

First, update the packages using the update command given below:

$ sudo apt update

Step 2: Install Dependencies

Now to build Python in Ubuntu from the source code, we have to install the required dependencies, and to do so, execute the below command.

$ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

Step 3: Create a Python Directory

Now create a new folder named Python and move within the folder. Use the following command to do so:

$ sudo mkdir /python && cd /python

It can be seen that a new folder is created

Step 4: Download Python Using wget

Now download the latest version of Python with the help of the wget command as shown below:

$ sudo wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0a1.tgz

It will take some time to download the Python package.

Step 4: Extract the “.tgz” File

Now extract the downloaded file with the help of the tar command, and to do that, run the command:

$ sudo tar -xvf Python-3.12.0a1.tgz

Now move within the extracted folder with the help of the command listed below:

$ cd Python-3.12.0a1

Step 5: Turn on Optimizations

It is essential to turn on optimizations to build Python in Ubuntu, and this can be done by executing the command.

The Python is now built on Ubuntu.

Step 6: Install Python

Now for Python installation, use the command.

$ sudo apt install python3

Check the version of Python by executing the command:

$ python3 -version

Conclusion

Ubuntu is an open-source Linux distribution that supports multiple programming languages such as Python, Java, etc. We can install Python on Ubuntu using multiple methods such as from the official Python repository, from the deadsnakes PPA, from the source code, etc. First, update the, then execute the sudo apt install python3 command to install Python on Ubuntu.

Frequently Asked Questions

How to install Python on Ubuntu 22.04 LTS from the Official Python Repository?

To install Python from the Official Python Repository on Ubuntu 22.04 LTS, update the packages using 'sudo apt update', then install Python using 'sudo apt install python3'. Verify the installation with 'python3 --version'.

What is the process to install Python on Ubuntu using Deadsnakes PPA?

To install Python on Ubuntu using Deadsnakes PPA, manage the distributions and add the PPA repository. Then, install the desired Python version using 'sudo apt install python3.x'. Verify the installation by running 'python3.x --version'.

How can Python be installed on Ubuntu from source code?

To install Python on Ubuntu from source code, download the Python source package, extract it, configure, compile, and install it. Make sure to follow the official Python documentation for detailed instructions.

What are the benefits of installing Python on Ubuntu for programming?

Installing Python on Ubuntu provides access to a wide range of Python libraries and tools for programming. It ensures compatibility with other Ubuntu software and facilitates seamless development environments.

Is it necessary to update system packages before installing Python on Ubuntu?

Yes, it is recommended to update system packages before installing Python on Ubuntu to ensure the system is up-to-date and reduce potential conflicts or compatibility issues with new installations.

How to check the Python version installed on Ubuntu?

To check the Python version installed on Ubuntu, run the command 'python3 --version' in the terminal. It will display the installed Python version, such as '3.10.12'.

Can multiple Python versions coexist on Ubuntu using Deadsnakes PPA?

Yes, multiple Python versions can coexist on Ubuntu using Deadsnakes PPA. You can install and manage different Python versions simultaneously to meet specific project requirements.

What is the significance of using Deadsnakes PPA for Python installation on Ubuntu?

Deadsnakes PPA is significant for Python installation on Ubuntu as it provides access to various Python versions not available in the default repositories. It simplifies managing different Python environments and versions.