how to install python 3.9 on ubuntu 20.04

How to Install Python 3.9 on Ubuntu 20.04

In the following article, we’ll walk through the installation of your Python 3.9 version with two options. Installing it directly from the APT repository or building the Python 3.9 from the source. Python is one of the world’s most popular programming languages.

install python 3.9 on ubuntu 20.04

It is a versatile language used to build all kinds of applications, from simple scripts to complex machine learning algorithms. With its simple and easy-to-learn syntax, Python is a popular choice for beginners and experienced developers. Next, you will learn how to install Python 3.9 on Ubuntu 20.04 version, using a few simple steps to complete this process.

Installing Python 3.9 on Ubuntu 20.04 with Apt

Below we’ll show you how to install Python 3.9 using the apt cli from Python, we just need to follow the following steps.

1 – We’ll start with the apt update and installation of the prerequisites.

apt update -y
apt upgrade -y
apt install software-properties-common

2 – Once you finish the update and prerequisites installation, we need to add the deadsnakes PPA to our system’s sources list. The following command will do that:

add-apt-repository ppa:deadsnakes/ppa

When prompted, you need to press [Enter] in order to continue.

3- Then, you just need to install the python with this command, once the repository is successfully added.

apt install python3.9

4- Once installed, you can verify the version installed with:

python3.9 --version
Output
Python 3.9.7

That’s it, you successfully installed python3.9 on your server using APT

Installing Python 3.9 on Ubuntu 20.04 from Source

The benefit to install Python from the source is that it allows you to install the latest Python version and customize the build options. However, you will not be able to maintain your Python installation through the apt package manager. Since it was installed from the source.

Bellow, we’ll learn how to do that.

1- Update your server and be sure to install the necessary dependencies to build python:

apt update -y
apt upgrade -y
apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev -y

2- Download the latest release source code from the Python download page with wget installed on the last step. In this tutorial we are using the 3.9.7, the latest one today.

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

3- Now, we need to extract the python compressed file with the following command:

tar -xvf Python-3.9.7.tgz

4- We’ll start the build of our Python now, let’s enter the directory now and start the configure script.

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

The flag –enable-optimizations is optional. It will optimize the python binary, but the build process will be slower.

5 – Starting the build process with the make command:

make

6 – When the build process is complete, we’ll install the Python binaries by typing:

make altinstall

7- Once the binaries are installed, you can test your python version with the following command:

python3.9 --version
Output
Python 3.9.7

That’s it, you successfully installed Python 3.9 on your Ubuntu 20.04 server. You can now run your python scripts using the latest version available. We hope this tutorial on Python will help you, and don’t forget to leave a reply of appreciation below, in the comments section.

Alternatively, in case you are out of time and need to automate things, you can always subscribe to one of our managed Linux hosting plans and let a team of industry experts do it for you, 100% free of charge. Thanks!

One thought on “How to Install Python 3.9 on Ubuntu 20.04

Leave a Reply

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