Python is the most widely utilized high-level language that comprises applications ranging from normal scripts to complicated machine learning algorithms. It is known for its straightforward conversion to newer releases and its basic, easy-to-learn syntax, which enhances readability and also reduces software maintenance costs.

More specifically, Python 3.9 is embedded with new syntax, built-in, standard library features, new library modules, and Interpreter improvements.

This write-up will discuss the procedure to install Python 3.9 on Ubuntu 22.04 using two different methods. So, let’s start!

How to Install Python 3.9 on Ubuntu 22.04 using APT

To install Python on Ubuntu 22.04 with APT, you must follow the below-given step-by-step instructions.

Step 1: Update system repositories


Press “CTRL ALT T” to open the terminal of the Ubuntu 22.04 and run the below-given command to update system repositories:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-1.png" data-lazy- height="616" src="data:image/svg xml,” width=”819″>

Step 2: Install prerequisite package


The next step is about the installation of the “software-properties-common” package:

$ sudo apt install software-properties-common

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-2.png" data-lazy- height="403" src="data:image/svg xml,” width=”807″>

Step 3: Add “deadsnakes” PPA


After fulfilling all of the prerequisites, move ahead and add the “deadsnakes” PPA to your system source list:

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

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-3.png" data-lazy- height="576" src="data:image/svg xml,” width=”818″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-4.png" data-lazy- height="575" src="data:image/svg xml,” width=”817″>

Step 4: Python 3.9 installation on Ubuntu 22.04


Now, execute the below-given command for installation of Python 3.9 on your Ubuntu 22.04 system:

$ sudo apt install python3.9

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-5.png" data-lazy- height="580" src="data:image/svg xml,” width=”819″>

Enter “y” to permit the installation process to continue:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-6.png" data-lazy- height="576" src="data:image/svg xml,” width=”819″>

Step 5: Verify Python version


Lastly, execute the “python3.9” command with the “–version” option to verify the installed version of Python:

As you can see, the given output signifies that we have successfully installed Python 3.9 on our Ubuntu 22.04:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-7.png" data-lazy- height="275" src="data:image/svg xml,” width=”821″>

Now, let’s check out the second method for the installation of Python 3.9 on Ubuntu 22.04.

How to install Python 3.9 on Ubuntu 22.04 from source

Installing Python from source has its advantages as it permits you to install the most latest Python version and tweak the build options. To avail this method, follow the below-given procedure.

Step 1: Install required dependencies


Firstly, utilize the given command for the installation of the required dependencies for Python 3.9:

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

After executing the above command, wait for a few minutes:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-8.png" data-lazy- height="624" src="data:image/svg xml,” width=”820″>

Step 2: Download compressed Python 3.9 package


Next, utilize the below-given “wget” command for downloading Python 3.9 compressed package:

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

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-9.png" data-lazy- height="451" src="data:image/svg xml,” width=”819″>

Step 3: Extract Python 3.9 package


Now, use the “tar” command to extract the content of the Python 3.9 downloaded compressed file:

$ tar -xvf Python-3.9.7.tgz

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-10.png" data-lazy- height="622" src="data:image/svg xml,” width=”817″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-11.png" data-lazy- height="618" src="data:image/svg xml,” width=”816″>

Step 4: Start building Python 3.9


To start building Python 3.9 on your Ubuntu 22.04 system, firstly, move to the “Python-3.9.7/” directory by utilizing the “cd” command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-12.png" data-lazy- height="253" src="data:image/svg xml,” width=”819″>

Then, start the “configure” script and add the “–enable-optimizations” option for optimizing the Python binary:

$ ./configure –enable-optimizations

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-13.png" data-lazy- height="626" src="data:image/svg xml,” width=”820″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-14.png" data-lazy- height="623" src="data:image/svg xml,” width=”821″>

After doing so, execute the “make” command for starting the Python 3.9 building process:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-15.png" data-lazy- height="627" src="data:image/svg xml,” width=”818″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-16.png" data-lazy- height="628" src="data:image/svg xml,” width=”819″>

After completing the build process, write out the following command for installing the Python 3.9 binaries:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-17.png" data-lazy- height="251" src="data:image/svg xml,” width=”811″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-18.png" data-lazy- height="620" src="data:image/svg xml,” width=”817″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-19.png" data-lazy- height="632" src="data:image/svg xml,” width=”825″>

Step 5: Verify Python version


Now, execute the “python3.9” command with the “–version” option to verify the installed version of Python:

As you can see, the given output signifies that we have successfully installed Python 3.9 on our Ubuntu 22.04:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-20.png" data-lazy- height="275" src="data:image/svg xml,” width=”821″>

How to remove Python 3.9 from Ubuntu 22.04

To remove Python 3.9 from Ubuntu 22.04, type out the following command:

$ sudo apt-get remove python3.9

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-to-Install-Python-21.png" data-lazy- height="580" src="data:image/svg xml,” width=”818″>

We have compiled two different methods for installing Python 3.9 on Ubuntu 22.04.

Conclusion

To install Python 3.9 on Ubuntu 22.04, you can use both APT and compressed Python 3.9 source file. By using APT, firstly, install the prerequisites and execute the “$ sudo apt install python3.9” command. While installing Python 3.9 from source, you have to download and install the Python 3.9 package and then build the Python binaries. This write-up discussed two methods for the installation of Python 3.9 on Ubuntu 22.04.

About the author

<img alt="" data-lazy-src="https://secure.gravatar.com/avatar/c73b74cd8044d2e9b300610f5af77d0b?s=112&r=g" data-lazy- height="112" src="data:image/svg xml,” width=”112″>

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.