How to Install Python 3.9 on Ubuntu 16.04

0 comments 9.2K views 3 mins read
Published on: December 2, 2022 | Last updated on: October 26, 2024

We’ll show you how to install python 3.9 on ubuntu! To get Python 3.9 running on Ubuntu LTS, you can choose one of two routes. Either download Python 3.9 from the deadsnakes PPA or compile it from scratch.


Python is a widely used programming language. There is no denying this. From the simplest of programs to the most complex machine learning algorithms, all are possible in this language. Python’s clear and logical grammar has made it a popular choice among programmers of all skill levels.

Downloads of Python 3.9, the most recent significant update to the Python programming language, are now available. A few examples of the many new features include new dict operators, str functions, and support for the IANA time zone. There have also been several more enhancements.


The installation process for Ubuntu is same across all variants based on Ubuntu, including Kubuntu, Linux Mint, and Elementary OS.

How to install Python 3.9 Using Apt on Ubuntu 16.04

This is an easy and quick way to install python 3.9 installed on Ubuntu using the apt package manager.

  1. Install the requirements and the current set of packages:
Bash
sudo apt update
Bash
sudo apt install software-properties-common

Add the deadsnakes PPA to the sources list of your system:

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

To proceed, you must hit [Enter] when instructed to do so.

Once the repository has been activated, you will be able to install Python 3.9 by issuing the following command:

Bash
sudo apt install python3.9

Type in the following to check that the installation was completed successfully:

Bash
python3.9 --version
Bash
Python 3.9.1+

That sums it up well. Python 3.9 is now ready for use on your Ubuntu system and has been successfully installed.

How to install Python 3.9 using the source code on Ubuntu 16.04

Compiling Python from its source code gives you the ability to install the most recent version of Python as well as tweak the build parameters. On the other hand, you won’t be able to use the apt package manager to manage and update your Python installation.

The compilation of Python 3.9 from its source code may be broken down into the following steps:

Install the prerequisites for building Python, which are as follows:

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

Using wget, get the source code for the most recent version of Python from the Python download page:

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

When the download is finished, you may extract the gzipped archive as follows:

Bash
tar -xf Python-3.9.1.tgz

Move to the directory containing the Python source code, and then execute the configure script. This script will carry out a series of tests to ensure that all of the necessary dependencies are available on your system.

Bash
cd Python-3.9.1./configure --enable-optimizations

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

Kick off the process of building Python 3.9:

Bash
make -j 12

Change the -j option to match to the number of cores in your CPU to make the building process go more quickly. Simply enter nproc into your search bar to get the number..

Once the Python binaries have been built, use the following command to install them into your system.

Bash
sudo make altinstall

Because we’ll be overwriting the system’s default python3 binary later, we’re using altinstall rather than install.

That’s all. Python 3.9 is now installed and ready for usage. To confirm, type:

Bash
python3.9 --version

The following Python version should be shown in the output:

Bash
Python 3.9.1

Conclusion

Python 3.9 is not included in the normal Ubuntu 16.04 repository.

We’ve taught you how to install Python 3.9 on your Ubuntu computer. You may now start building your Python 3.9 project.

Let us know what you think in the comments section below..