If you’re a developer, I’m sure you’re already familiar with the language “Python”. With Its increasing popularity over the years, i’t used for building almost all kinds of applications, from simple scripts to complex algorithms for machine learning.
Due to its simplicity and closeness to English syntax, most beginners are advised to get started with Python in order to understand Programming fundamentals. Its object-oriented approach furthermore helps the developer in writing simpler, clearer and easy to understand code since the beginning.
In this article we’ll learn how to install the version 3.9 of Python on our Ubuntu 20.04. The 3.9 version of Python comes with various new features such as new dict and str operators and many more. So follow the guide provided below for error free installation.
Step By Step Guide for Installation
There are various ways to install Python 3.9. Follow the steps provided below. You can install it using Apt as well as from the source. Both steps are provided below:
Installation Using Apt
The installation of Python 3.9 using apt is a simple straightforward step.
Step 1: Update your system and Install Dependencies
Firstly, you need to update your system:
$ sudo apt update
Now, you need to install some dependencies required before installation:
$ sudo apt install software-properties-common
Step 2: Adding PPA
Here, we need to add the deadsnakes PPA to the source list of our system:
$ sudo add-apt-repository ppa:deadsnakes/ppa
This will give you the following message:
Just simply press enter to continue and complete the process.
Step 3: Installation of Python 3.9
Now that all arrangement and required dependencies are installed, it’s time to install Python:
$ sudo apt install python3.9
This will take a few seconds. Now we’ve successfully installed Python 3.9, in order for verification check the version:
$ python3.9 --version
Now you’ve successfully installed python on your Ubuntu 20.04.
Installation Using Source
Another way to install Python 3.9 is using the source.
Step 1: Update your system and Install Dependencies
Firstly, you need to update your system:
$ sudo apt update
Now, in order to build Python some dependencies should be installed:
$ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
Step 2: Download Source Code
After all this, we’ve to download the latest source code version from the website using “wget”:
$ wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
After the download is complete we need to extract the file:
$ tar -xf Python-3.9.1.tgz
After this, we need to go the the Python source directory:
$ cd Python-3.9.1
Here, we need to check whether all the dependencies required are present. To ensure that configuration script will run:
$ ./configure --enable-optimizations
Step 2: Download Source Code
Now, we are all set and just need to build the python 3.9. For this:
$ make -j 12
In order for a faster build time, simply write the number of cores in your processors along with j. Now after it’s completed, install the binary files:
$ sudo make altinstall
Here, we used altinstall instead of install in order to overwrite the files later. Now simply verify the version:
$ python3.9 --version
Now, you’ve installed the python 3.9 version successfully.
Conclusion
Python is a widely growing programming language that is being used for all types of purposes. From machine learning to developing games. Here in this tutorial we showed you installation of Python 3.9 on Ubuntu 20.04. We showed you two different ways, apt and through using sources. By following the above steps you’ll have an error-free installation by the end of this article.
Check our LinkedIn company page