How to Install Python 3.9 on Ubuntu 20.04
3 min read
Python is one of the world’s most popular programming languages. It is a versatile language used to build all kinds of applications, from simple scrips to complex machine learning algorithms. With its simple and easy to learn syntax, Python is a popular choice for beginners and experienced developers.
Python 3.9 is the latest major release of the Python language. It includes many new features such as new dict operators, new str functions, support for IANA time zone, and more .
In this article, we’ll show you two ways to install Python 3.9 on Ubuntu 20.04. The first option is to install the package from the deadsnakes PPA, and the second one is to build Python 3.9 from the source code.
The same steps apply for Ubuntu 18.04 and all Ubuntu-based distribution, including Kubuntu, Linux Mint, and Elementary OS.
Installing Python 3.9 on Ubuntu with Apt
Installing Python 3.9 on Ubuntu with apt is a relatively straightforward process and takes only a few minutes to complete.
Update the packages list and install the prerequisites:
sudo apt update
sudo apt install software-properties-common
Add the deadsnakes PPA to your system’s sources list:
sudo add-apt-repository ppa:deadsnakes/ppa
When prompted, press
Once the repository is enabled, you can install Python 3.9 by executing:
sudo apt install python3.9
Verify that the installation was successful by typing:
That’s it. Python 3.9 is installed on your Ubuntu, and you can start using it.
Installing Python 3.9 on Ubuntu from Source
Compiling Python from the source allows you to install the latest Python version and customize the build options. However, you won’t be able to maintain your Python installation through the
apt package manager.
The following steps explain how to compile Python 3.9 from the source:
Install the dependencies necessary to build Python:
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
Once the download is complete, extract the gzipped archive :
tar -xf Python-3.9.1.tgz
Switch to the Python source directory and run the
configurescript, which performs a number of checks to make sure all of the dependencies on your system are present:
--enable-optimizationsoption optimizes the Python binary by running multiple tests. This makes the build process slower.
Start the Python 3.9 build process:
make -j 12
For faster build time, modify the
-jto correspond to the number of cores in your processor. You can find the number by typing
When the build process is complete, install the Python binaries by typing:
sudo make altinstall
installbecause later will overwrite the default system python3 binary.
That’s it. Python 3.9 has been installed and ready to be used. To verify it, type:
The output should show the Python version:
Python 3.9 is not available in the standard Ubuntu 20.04 repositories.
We’ve shown you how to install Python 3.9 on your 20.04 machine. You can now start developing your Python 3.9 project.
If you have any questions or feedback, feel free to comment below.