How to Install Python 3.9 on Ubuntu 20.04

how to install python 3.9 on ubuntu 20.04

Python is the most popular high level general purpose programming language in the world. Python is used for Web development, software development, game development, machine learning, data science and more. Python is easy to learn for beginners.

In this tutorial we are going to learn how to install python 3.9 on ubuntu 20.04 at the time of writing this python installation article python 3.9.4 is the latest version of python.

We will install python 3.9 on ubuntu 20.04 with following two steps:

  • Install python 3.9 on Ubuntu from Official Source
  • Install python 3.9 Ubuntu with apt

Install Python 3.9 from Official Source:

Let’s begin the Python 3.9 installation on Ubuntu 20.04 from official source.

Update the Packages:

Before installing Python 3.9 on Ubuntu 20.4 update the Ubuntu packages.

sudo apt update
Install Python Dependencies:

After updating the Ubuntu packages install the required Python dependencies.

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libsqlite3-dev wget libbz2-dev libnss3-dev libssl-dev libreadline-dev libffi-dev
Download and Extract Python 3.9 Source Code:

Download the latest Python 3.9.4 code from official source with following command.

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

After downloading the latest version python 3.9.4 code from official source now extract the code.

tar -xf Python-3.9.4.tgz

After extracting the Python Source Code, move to the Python directory.

cd Python-3.9.4.tgz
System Check and Optimization:

Now run configure script to check all the dependencies are installed on your Ubuntu 20.04 system. To enable optimizations add the --enable-optimizations tag.

./configure --enable-optimizations

This process will take sometimes.

Start Python Build Process:

Before starting the Python build process check the number of CPU cores of your Ubuntu 20.04 system.

To check the number of CPU cores run the command below.

nproc

After that start python build process with make command. Replace the CPU core number based on your Ubuntu 20.04 system.

make -j 4
Complete Python 3.9 Installation:

After successful build process of python 3.9 now complete the python installation on Ubuntu 20.04.

sudo make altinstall

Use altinstall don’t use install because this disturbs the default Python3.

Verify Installation:

To verify the successful installation of Python 3.9 on your Ubuntu 20.04 system run the command below.

python3.9 --version
Output:

python3.9.4

Install Python 3.9 with apt:

This is the simple method to install Python 3.9 on Ubuntu 20.04 system.

Before installing python 3.9 on Ubuntu 20.04 update the packages and install required software packages.

Update the Packages:

To update the packages run the command below.

sudo apt update
Install Required Software:

To install the required software run the command below.

sudo apt install software-properties-common
Add Deadsnakes PPA:

To add the deadsnakes PPA run the command below.

sudo add-apt-repository ppa:deadsnakes/ppa

This will prompt you to click the ENTER click and proceed.

Install Python 3.9:

To install Python 3.9 on Ubuntu 20.04 system run the command below.

sudo apt install python3.9
Verify Installation:

To verify the successful installation of Python 3.9 on your Ubuntu 20.04 system run the command below.

python3.9 --version
Output:

python3.9.4

Conclusion:

Successfully we have installed python 3.9 on Ubuntu 20.04. In this tutorial we have learned two methods of how to install python 3.9 on Ubuntu 20.04. Hope this helps.

Next Article: How to Install Go on Ubuntu 20.04

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like