How to install Python on Linux (Ubuntu) - For beginners with pictures

Python Exercise Lists

Linux systems are built for programming, thus most of Linux distribution (such as Ubuntu, CentOS, etc.) come with Python by default. Some Linux distributions even come with two version of Python. For instance, the latest version of Ubuntu comes with Python 2.x and Python 3.x.

1. Open the terminal which built in the Linux distribution therefore key in “Python” to detect whether Python has installed and what is the installed version of Python.


2. You can see the Python version which indicates that the current Linux distribution comes with Python version. The Python command prompt >>> indicates we have entered the Python interactive programming environment.


3. Key in “exit()” to exit the Python programming environment and return to the Linux command line. Majority of Linux distributions come with Python 2.x instead of Python 3.x. Key in “Python3” in the Terminal to check the current Python version in the Linux distribution.

If the Python3 command runs successfully and symbol >>> appears on the Python prompt, it indicates that the current Linux distribution has installed the Python 3 development environment. Thus, you can start to use Python3.

However, if current Linux does not install Python 3, or you feel that the existing Python 3 version is not the latest version, you can update the Python version. For this case, we use Ubuntu as an example.

How to update Python version on Ubuntu (With pictures)

1. Update the Python version by executing the following two commands in Ubuntu terminal:

$sudo apt-get update

$sudo apt-get install python3.8

Explanation of two commands:

The first command: used to update the source addresses listed in /etc/apt/sources.list and etc/apt/sources.list.d, it can help to ensure that the latest installation package is obtained.

The second command: used to specify the version of Python that you would like to update to.

Wait for the execution of the above two commands and enter the Python3 command in the terminal again. You can see the Python interactive programming environment has been updated to Python 3.8.

Python Reinstallation

If you do not have Python environment in Ubuntu or you want to reinstall, then you can follow here.

1. Download the source code from the official website.

Python official address:

You can see various versions of Python after clicking on the link.

2. Look for the Python version that you want to install then download it.

3. Click either the Python version number or “Download” button in the figure below in order to enter the download page. Therefore, scroll to the end of the page to look for Python installation packages for each platform.

4. Right-click on the “Gzipped source tarball” and select “Copy link address” from the pop-up menu in order to get the source code archive address in .tgz format.

5. Paste the link address after wget:

$ wget

6. Extract the source package. For this case, it is Python-3.8.1.tgz

$ tar -zxvf Python-3.8.1.tgz

6. Compile using the make tool:

$ ./configure --prefix=/usr/local

$ make&&sudo make install

The --prefix=/usr/local is used to specify the installation directory. if nothing mentioned here, therefore the default installation directory will be used.

Finally, we have installed Python, now you can verify again whether the installation is successful using the same method mentioned above.


More Tutorials:

Python Installation - Linux (Ubuntu)
Python Installation - Mac OS
Integrated Development Environment - IDE
Python - Basic Variables
Python - Sequence Introduction
Python - Output Formatting
Python - Escape Character
Python - Type Conversion
Python - Numbers
Python – Arithmetic Operators
Python – Assignment Operators
Python – Comparison Operators
Python – Logical Operators
Python – Precedence and Associativity Operators
Python – Bytes Type and Usage
Python – Long & Raw Strings
Python – Concatenate Function
Python – Slice Function
Python – Length and Split Function
Python – Join and Count Function
Python – Find Function
Python – Index Function
Python – Alignment Function
Python – Startswith and Endswith Function
Python – String Case Conversion
Python – Remove Specified Character
Python – Encode and Decode Function
Python – dir and help Function
Python – Input Output Introduction
Python – Basic Operation
Python – Open Function
Python – Read Function
Python – Readline Function
Python – Write Function
Python – Close Function
Python – Seek and Tell Function
Python – Pickle Module
Python - File Input Module and Linecache Module
Python - Pathlib Module
Python - Pathlib Module
Python - os.path Module
Python - fnmatch Module
Python - Tuple Introduction
Python - List Introduction
Python - List Add Element
Python - List Delete Element
Python - List Modification Element
Python - List Find Element
Python - Dictionary Introduction
Python - Dictionary Basic Operation
Python - Dictionary Method Guide
Python - Set Collection
Python - Set Basic Operation
Python - Set Basic Method
Python - Frozenset Method
Python - If Condition I
Python - If Condition II
Python - While loop
Python - For loop
Python - Pass Statement
Python - Break Statement
Python - Zip Reverse Function
Python - Function Introduction
Python - Positional Parameters
Python - Key Arguments
Python - None and Return
Python - Variable Scope
Python - Local Function
Python - Closure Method
Python - Lamdba Expression

More Python Exercises:

Python String Exercises
Python List Exercises
Python Library Exercises
Python Sets Exercises
Python Array Exercises
Python Condition Statement Exercises