Cybersecurity Updates & Tools

Install Python 3.9: Easy Ubuntu 20.04 Setup Guide

If you’re looking to Install Python 3.9 on Ubuntu 20.04, there are two reliable methods available. You can either use a trusted package repository for a quick installation or compile Python from source to gain access to the latest features and customization options.

Python remains one of the most widely used programming languages for web development, automation, artificial intelligence, data science, and system administration. Python 3.9 introduced several improvements, including enhanced dictionary operations, new string methods, and better time zone support, making it a popular choice among developers.

In this guide, you’ll learn how to install Python 3.9 on Ubuntu 20.04 using both methods.

Why Install Python 3.9 on Ubuntu?

Ubuntu 20.04 ships with an older Python version by default. While it works well for many applications, developers often need newer Python releases to access updated features, improved performance, and better compatibility with modern frameworks.

Installing Python 3.9 alongside the system version allows you to use the latest capabilities without affecting critical Ubuntu components.

Install Python 3.9 Using APT Repository

The easiest way to install Python 3.9 is through a trusted third-party repository that provides updated Python packages for Ubuntu.

First, update your package list and install the required tools:

sudo apt updatesudo apt install software-properties-common

Next, add the repository that contains Python 3.9 packages:

sudo add-apt-repository ppa:deadsnakes/ppa

After enabling the repository, install Python 3.9:

sudo apt updatesudo apt install python3.9

Verify the installation:

python3.9 --version

If everything is successful, Ubuntu will display the installed Python version.

Install Python 3.9 from Source Code

Developers who want maximum control over their Python installation can build it directly from source code.

Start by installing the necessary build dependencies:

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

Download the Python source archive and extract it:

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

Move into the extracted directory:

cd Python-3.9.1

Configure the build process:

./configure --enable-optimizations

Compile Python:

make -j $(nproc)

Finally, install it without replacing Ubuntu’s default Python version:

sudo make altinstall

Confirm the installation:

python3.9 --version

Verify Your Python Environment

After you install Python 3.9, it’s a good idea to ensure the interpreter is functioning correctly.

Run:

python3.9

You should enter the Python interactive shell, where you can execute commands and test functionality immediately.

For development projects, consider creating isolated virtual environments to manage dependencies efficiently and avoid package conflicts.

Conclusion

Choosing to Install Python 3.9 on Ubuntu 20.04 gives developers access to modern language features, improved performance, and broader compatibility with current applications. Whether you use the faster repository-based method or compile from source for greater flexibility, both approaches provide a dependable way to Install Python 3.9 while keeping your Ubuntu system stable and secure.