Table of Contents
In this article, I will take you through the steps to Install Python 3 on Ubuntu 20.04. Python is a very popular open source interpreted high level programming language. Developers and Programmers love to code in this language due to its easy integration with other programming languages. While there are many ways to install python 3 on Ubuntu 20.04 but here we will focus on the most simplest way. More about Python 3
What is Python
Python is an open source object oriented programming language written in C by Guido van Rossum. It is often used to build software and applications for multiple environments and platforms. In fact, it is one of the most used programming language in the world.
Features of Python Programming Language
- Easy to understand language.
- It is a dynamically typed language.
- It is supported on almost all kind of Infrastructure.
- It supports object oriented features like Inheritance, polymorphism etc.
- It can be easily integrated with other languages due to its large standard library support.
- It supports huge number of GUI Frameworks.
- It is less complex as compared to other object oriented programming languages like C++ and Java.
- Compiling and Debugging is fairly easy.
- It has excellent Garbage Collector feature for Memory Management.
How to Install Python 3 on Ubuntu 20.04
Also Read: How to Fix Broken Packages in RHEL/CentOS 7/8{Easy Methods}
Step 1: Prerequisites
a) You should have a running Ubuntu 20.04
Server.
b) You should have sudo
or root
access to run privileged commands.
c) You should have apt
or apt-get
utility installed in your Server.
Step 2: Update Your Server
Before you think about installing any new package it is always advised to run system wide update once using apt update
or apt-get update
command as shown below. It will install all the latest versions of your packages and reduce the chances of any broken package error.
root@localhost:~# apt update
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:4 https://packages.microsoft.com/repos/edge stable InRelease [7,343 B]
Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [545 kB]
Ign:7 http://ppa.launchpad.net/oguzhaninan/stacer/ubuntu focal InRelease
Get:8 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1,262 kB]
Get:9 https://packages.microsoft.com/repos/edge stable/main amd64 Packages [8,011 B]
Get:10 http://ppa.launchpad.net/micahflee/ppa/ubuntu focal InRelease [17.5 kB]
Step 3: Install Python 3.8
While you can install any of the python3 version package based on your requirement but here we will install the latest one that is python3.8 using apt install python3.8 -y
or apt-get install python3.8 -y
command as shown below.
root@localhost:~# apt install python3.8 -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
python3.8-venv python3.8-doc
The following NEW packages will be installed:
python3.8
0 upgraded, 1 newly installed, 0 to remove and 199 not upgraded.
Need to get 0 B/387 kB of archives.
After this operation, 521 kB of additional disk space will be used.
Selecting previously unselected package python3.8.
(Reading database ... 179216 files and directories currently installed.)
Preparing to unpack .../python3.8_3.8.10-0ubuntu1~20.04.1_amd64.deb ...
Unpacking python3.8 (3.8.10-0ubuntu1~20.04.1) ...
Setting up python3.8 (3.8.10-0ubuntu1~20.04.1) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...
Step 4: Check Python Version
You can check the installed version of python using python3.8 --version
command. So as you can see it is 3.8.10
.
root@localhost:~# python3.8 --version
Python 3.8.10
Step 5: Write Your First Python Program
Now you must be thinking how can we verify the usage of python tool. Well, you can write a simple python file and run it to confirm. For example here we are writing a simple python program to print hello world
on the output. We are creating a new file called hello.py
using our favorite nano
editor and writing a print statement to display hello world
as shown below.
root@localhost:~# nano hello.py print('Hello World !!') root@localhost:~# python3.8 hello.py Hello World !!
Step 6: Remove Python 3.8
You might be thinking if we can remove python3.8 which we have installed earlier. Well I would suggest not to as it might be possible that there are certain program relying on this version gets affected. But if you are absolutely sure that you don't need it anymore then you can remove it by simply using apt remove python3.8 -y
or apt-get remove python3.8 -y
command as shown below.
NOTE:
apt remove python3 -y
or apt-get remove python3 -y
command even by mistake as it will not ask for your confirmation before removing all the python3 related packages. Running this command will have disastrous effect of your Server. Hence be careful with the command you run especially if you are running on a production Server.root@localhost:~# apt remove python3.8 -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
python3.8-minimal
Use 'apt autoremove' to remove it.
The following packages will be REMOVED:
python3.8
0 upgraded, 0 newly installed, 1 to remove and 199 not upgraded.
After this operation, 521 kB disk space will be freed.
(Reading database ... 179235 files and directories currently installed.)
Removing python3.8 (3.8.10-0ubuntu1~20.04.1) ...