How to Install Python in Ubuntu Through Terminal

  • Last updated: September 13, 2024 By Sunil Shaw

How to Install Python in Ubuntu Using Terminal

Introduction

Python is a popular programming language used for automation, web scraping, artificial intelligence, and other fields. At the time of writing this article python’s latest version is 3.12. Almost every Linux based distro comes with a version of Python included in the default system packages. As All Linux distribution have Python pre-installed. May be there is chance due to some reason your OS didn’t have Python pre-installed.

In this article you will learn how to install python in ubuntu through terminal.

Prerequisites

  • A system running with Ubuntu 22.04
  • Access to the terminal
  • A User with Root Privilages

How to Check Python Version in Linux Terminal

Let’s take a closer look how you can find default python version in Ubuntu. Before installing Python, check weather you have it on your system. Open your terminal and run the following command.

python --version

For Python3

Method 1: Simply you have to run the command python3 --version

python3 --version

Terminal Output:

Python 3.10.12
How to Check Python Version in Linux Terminal

Method 2: Write this simple command python3 on your terminal and hit the Enter button

python3

Terminal Output:

Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
How to Check Python Version in Linux Terminal Output

Now you have to exit, Use Python built-in function exit()

exit()
How to Check Python Version in Linux Terminal Output exit()

Install Python in Ubuntu Through Terminal

There a various method to install Python in ubuntu through terminal.

  • Using APT: Install latest available python version in the default ubuntu repository.
  • Using PPA: Python can be installed from deadsnake PPA. Deadsnake is an third party service provider.

Below i explained the process to install python, choose one of them that best fits to you.

Method 1: Install Python With APT

This method uses Advanced Package Tool or APT. APT is an default package manager for ubuntu and other debian based distribution. This method is most famous and popular because of simplicity and easiest way but it may not install latest version of python. If you want to know the latest version of python visit their website.

Follow these steps:

Step 1: Update System Repository

  1. Open your terminal by pressing CTRL + ALT+ T.
  2. Update the package repository to get the latest program version. Type this below command and hit enter command to run it .
sudo apt update

If you done it, already or you updated then just move to next step.

Step 2: Install Python

Running command sudo apt install python3 means we telling sudo to run advanced package tool to install python3.

sudo apt install python3

Wait to finish installation process to start using python. If you have slow internet connection it may take more time than regular.

Step 3: Verify Python installed Or Not

python3 --version

Method 2: Install Python With PPA

Meanwhile, for any reason if you are not able to install Python by using APT from Ubuntu official repository, You can try this method. Try to add Deadsnakes PPA to your repository list.

PPA stands for Personal Package Archive a third party repository in ubuntu that provides easiest way to access and install the newer versions of program resources, which one is not available in Ubuntu default system repository. PPA is designed sepcially only for Ubuntu users.

In this article I am going to demonstrate about Deadsnake PPA, There is lots of other available PPA. Follow these step.

Step 1: Update and Refresh System Repository Lists

Open your terminal and run this command.

sudo apt update

Step 2: Install Supportive Software

Unfortunetly you can’t add PPA’s directly to repository list. The software-properties-common packages give to more and better control over package managing and letting you add Personal Package Archives to repository.

Install this package by running below command.

sudo apt install software-properties-common

Step 3: Add the Deadsnakes PPA to Repository

Remeber Deadsnakes ppa have newer versions of program than deafult system repository, Run below command to add.

sudo add-apt-repository ppa:deadsnakes/ppa

Now, again update and refresh your system repository lists.

sudo apt update

Step 4: Install Python From Deadsnakes PPA

To install Python’s latest version.

sudo apt install python3

Deadsnakes have lots of Python version available in their database, you can add the version name and download it.

To install Python3.5 Version

sudo apt install python3.5

To install Python3.9 Version

sudo apt install python3.9

Deadsnakes also have older versions, if you want then you can install as per requirements.

Step 4: Verify

Verify that does Python installed correctly or not. Run the below command.

python3 --version

Note: If you don’t want to change the default version of Python3. Try Universe repository

Also, you can install Python 3.9 in Ubuntu 20.04 even without the deadsnake PPA with below commands.

sudo add-apt-repository universe
sudo apt update
sudo apt install python3.9

Conclusions

Now you know how to install Python. If you want to know what is Python You can Read Here. If you didn’t know about what is pep8 you must read it.

Download whole project from GitHub.


Follow on:
  • Twitter
  • Facebook
  • Instagram
  • Linkedin
  • Linkedin
Sunil Shaw

Sunil Shaw

  • Youtube
  • Instagram
  • Twitter
  • Facebook
About Author

I am a Web Developer, Love to write code and explain in brief. I Worked on several projects and completed in no time.

Related Articles

Popular Language Tutorials

If You want to build your own site Contact Us