How to install Python in Ubuntu – Step by Step Guide

Last updated on September 3rd, 2022

Python is among the well-known and most prominent programming languages. It is often employed for writing scripts for operating systems. Python is highly versatile when it comes to web development and app designing.  If you are the one wanting to know the apt process to install Python on an Ubuntu computer, you have got the right place to be. Here you will get insightful detail on everything you need to know, from installation command to update the latest version and beyond.

We can find rarely any Linux distribution not coming with any version of Python. Python is found almost with every Linux distribution that is incorporated in the default system packages. However, sometimes, you might not have Python installed on an Ubuntu system due to any reason. Dive into the subsequent sections to take a closer look at the insights on how to install python in ubuntu along with a brief guide on how to update the Python package.

First, confirm if Python script is available on your system or not

Python is considered a robust and high-level scripting language. It is employed by numerous developers worldwide. The Python language is perfect for a wide range of real-world applications. For instance, it functions ideal for web development, web scraping, penetration testing, etc. Further, you can also utilize Python for building a Telegram bot. 

Before you do anything else, you need to confirm if Python script is installed on your unit or not. In order to confirm whether you need to install Python on ubuntu or not, follow the below steps –

  • Open up your terminal by holding  Ctrl + Alt + T. 
  • Then, type in the keyword “Python.”
  • At last, press the enter key. 

After this process, if the following output appears in your terminal, it will indicate that Python is already installed on your computer. 

Python 3.9.1 (default, Dec 13 2020, 11:55:53) 

[GCC 10.2.0] on linux

Type “help”, “copyright”, “credits” or “license” for more information.


This output enables you to know about the details on the Python version running in your system (along with the current date and time).  

However, if instead, an error appears stating “bash: python: command not found”, then you must know that the Python is not installed in your Ubuntu system. 

Moreover, you also have the possibility to check the Python version by directly entering the given below command in your terminal.

python –version

This output will mention the details about the version of Python that is installed on your computer. 

How to install Python in Ubuntu?

Understanding and Implementing the process to install Python on Ubuntu is quite straightforward. You can acquire the latest version of Python on your Ubuntu system through various sources. The subsequent sections provide insights into different ways on how to install Python in Ubuntu.

1. Use the apt package manager to install Python

The “Apt” term is known as the Advanced Package Tool. It serves as the default package manager that you can have available on your Ubuntu system. So, the official Ubuntu repository lets you easily download the Python package. Here are the steps on how you can execute the same – 

  • First of all, open up your terminal by pressing the combination of Ctrl + Alt + T.
  • Further, you need to update your local system’s repository list. This can be done by executing the following command:

sudo apt-get update

  • In the next step, download the latest version of Python by implementing the command:

sudo apt-get install python

apt package manager to install Python
  • In the end, the Advanced Package Tool will be able to automatically discover the package. And it will install Python on your system.

2. Use Deadsnakes PPA to Install Python on Ubuntu

There can be a situation where you are not able to download the Python script package with the help of the official Ubuntu repository. In such a case, you can attempt to do the same by appending the Deadsnakes PPA to your system repository list. The PPAs are called Personal Package Archives. These are the repositories that are uniquely developed for Ubuntu users. Further, you cannot append PPAs to your system’s package lists by default. However, the “software-properties-common” package enables you to access an effective way to handle and control PPAs to your system. Peek into the following points to know the steps you need to follow – 

  • Type the following command to install the “software-properties-common” package

sudo apt-get install software-properties-common

Deadsnakes PPA to Install Python
  • Then, you need to append the official Deadsnakes PPA link to your system’s repository list. You can do this by executing the command:

sudo add-apt-repository ppa:deadsnakes/ppa

Deadsnakes PPA to Install Python
  • In the next step, you are required to update your system’s package lists by implementing the command:

sudo apt-get update

Deadsnakes PPA to Install Python
  • At last, you can download the latest version of Python from the appended PPA:

sudo apt-get install python3

Deadsnakes PPA to Install Python

You will have the opportunity to install the older versions of Python as the Deadsnakes PPA contains almost every version of Python in its database. All you will be required to do is substitute the package name with the version of Python, which you wish to install on your system. For instance, 

  • sudo apt-get install python3.2
  • sudo apt-get install python3.3
  • sudo apt-get install python3.8

3. Use Source Code to Install Python

Another way to install Python on Ubuntu system is to download and create the latest version of Python directly from the official Python website. Many users feel that compiling the source code can be a bit complicated process. However, if you follow the right process that we have mentioned below, you will easily be able to install Python on your system.

  • Execute the command in order to update your system’s local repository list:

sudo apt-get update

Source Code to Install Python
  • Then, you have to install supporting dependencies on your system with Apt using the following command:

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

Source Code to Install Python
  • Further, create a new directory for storing the Python source files:

mkdir /python && cd /python

Source Code to Install Python
  • After the above step, you can download the Python source code from the official FTP server by the command :

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

Source Code to Install Python
  • Next, the downloaded TGZ file needs to be extracted:

tar -xvf Python-3.9.1.tgz

Source Code to Install Python
  • You must perform analyses and optimizations before you actually install Python. This will help you to enhance the execution of your code by 10-20 percent. For this, utilize the command:

cd Python-3.9.1

./configure –enable-optimizations

Source Code to Install Python
  • At last, create the package with the help of MakeFile present in the directory:

sudo make install

Source Code to Install Python

Once you get done with all the above steps, ensure that the Python has got installed on your system by entering python –version in your terminal. Also, you must note that Python modules are controlled through PIP. PIP serves as a package management system. It is employed to download and add libraries from the Python Package Index. You should install Python PIP on your system in case you need to employ modules on your Python project.

How to Update the latest version of Python?

You must figure out whether you have an outdated version of Python that is installed on your Ubuntu system or not. You can check this out by entering the python –version in your terminal. Then, you can write down the details of the version.

Furthermore, you must discover the latest version of the script available. You can just google search with the keywords “python latest version” and that will be enough. If the result you acquire does not match with the version details of your installed Python, it can be the case that you are likely running an outdated version.

So, now you can look forward to upgrading your Python version. Ubuntu’s Advanced Package Tool enables you to easily upgrade to the latest version of Python. You can directly execute the given command if your Python is installed with Apt or the Deadsnakes PPA :

sudo apt-get install python

Moreover, you can utilize the –only-upgrade flag for updating update your packages further:

sudo apt-get –only-upgrade install python

On the other side, if you have compiled the source code of Python on your own, you need to move to the Python FTP for obtaining a copy of the latest version. And, then you will require to perform the actions all over again. 

Start Running Python on Ubuntu

Most likely, you will not be required to install Python on Linux. This is because Python comes as a preinstalled script in Linux. Further, you can also have Python available on official distribution repositories. However, if the Python still does not come already installed, you get the possibility to easily download it while employing Ubuntu’s package manager.

The significance of programming languages has become quintessential because of the rapidly progressing demand for developers in industries all over the globe. The programming language, Python, is utilized in varied sectors. One can know how powerful it is by seeing and working with the applications made by Python. 

Recommended: Linux vs Windows Dedicated Server: What to Choose?

Get in Touch

Arpit Saini

He is the Director of Cloud Operations at Serverwala Cloud Data Centers Pvt Ltd and also follows a passion to break complex tech topics into practical and easy-to-understand articles. He loves to write about Web Hosting, Software, Virtualization, Cloud Computing, and much more.

Related Articles

Adblock Detected

Please consider supporting us by disabling your ad blocker