Site icon Edumotivation

How to Install Python 3.9 on Ubuntu 20.04

How to Install Python 3.9 on Ubuntu 20.04

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics.

Python has become one of the most popular programming languages in the world in recent years. It’s used in everything from machine learning to building websites and software testing. It can be used by developers and non-developers alike.

Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together.

Python’s simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. It supports modules and packages, which encourages program modularity and code reuse.

The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed.

Often, programmers fall in love with Python because of the increased productivity it provides.

Since there is no compilation step, the edit-test-debug cycle is incredibly fast. Debugging Python programs is easy: a bug or bad input will never cause a segmentation fault.

Key Features in Python Programming Language:

Most used programming languages among developers worldwide, as of 2021

You don’t want to waste your time. If you’re going to put aside the time and energy needed to learn new programming languages, you want to make sure, without a doubt, that the ones you choose are the most in-demand programming languages on the market.

According to Statista’s Aug-2021 Developer Survey, JavaScript currently stands as the most commonly-used language in the world (64.96%), followed by HTML/CSS (56.07%), Python (48.24%) and SQL (47.08%).


Credit: Statista

This guide shows two ways of installing Python 3.9 on Ubuntu 20.04.

Prerequisites

In order to complete this tutorial, you should have a non-root user with sudo privileges on an Ubuntu 20.04 server.

This guide shows two ways of installing Python 3.9 on Ubuntu 20.04.

Method 1: Installing Python 3.9 from Source

Compiling Python from the source allows you to install the latest Python version and customize the build options.

Step #1

Open a terminal (CTRL+ALT+T) and execute the below commands to update packages.

$ sudo apt update && sudo apt upgrade

Step #2

Install the necessary dependencies to build Python.

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

Step #3

Download the latest Python source code package from the official website. You can do so using wget Command.

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

Step #4

Once the download is complete extract the .tgz file with the help of tar command.

$ tar -xf Python-3.9.7.tgz

Step #5

Change to the extracted directory with cd command, then prepare the Python source code for the compilation on your system.

$ cd Python-3.9.7
$ ./configure --enable-optimizations

The --enable-optimizations option optimizes the Python binary by running multiple tests. This makes the build process slower.

Step #6

Start the Python 3.9 build process.

$ make -j 12

For faster build time, modify the -j to correspond to the number of cores in your processor. You can find the number by typing nproc.

Step #7

Once build process is complete, finally run the following command to complete the Python installation.

$ sudo make altinstall

altinstall prevents the compiler to override default Python versions.

At this step, you have successfully installed Python 3.9 on Ubuntu 20.04 system. Type the following command to verify the same.

$ python3.9 --version

Python 3.9.7

Method 2: Installing Python 3.9 using Apt

Step #1

Installing Python 3.9 using apt is a relatively easy process and takes only a few minutes to complete.

Open a terminal (CTRL+ALT+T) and execute the below commands to update packages.

$ sudo apt update && sudo apt upgrade

Step #2

Install the prerequisites.

$ sudo apt install software-properties-common

Step #3

Type the following command to add the deadsnakes PPA to your system’s sources list.

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

The system will prompt you to press [Enter] to continue. Do so, and allow it to finish.

Note: deadsnakes PPA contains more recent Python versions packaged for Ubuntu.

Step #4

Now execute the following command to start the Python 3.9 installation.

$ sudo apt install python3.9

Type the following command to verify that the installation was successful.

$ python3.9 --version

Python 3.9.7

Conclusion

I hope that now you have a good understanding of How to Install Python 3.9 on Ubuntu 20.04 LTS Focal Fossa.

If anyone does have any questions about what we covered in this guide then feel free to ask in the comment section below and I will do my best to answer those.

Exit mobile version