Home  »  ArticlesHow ToLibrariesProgrammingTechnologyTools   »   How to Install Python 3.10 on Ubuntu 22.04

How to Install Python 3.10 on Ubuntu 22.04

This guide will show you how to install Python 3.10 on Ubuntu 22.04 or the latest Debian based Linux systems.

Getting You System Ready

First off, you will need to run a quick update to ensure your system is up-to-date with the required packages.

$ sudo apt update && sudo apt upgrade -y

Method 1: Install Python 3.10 on Ubuntu 22.04 Using the APT Utility

This is probably the easier method of installing the programming tools. This method makes it easy to receive continued updates, bug fixes, and security patches. With this option we need to install the relevant PPAs.

Let’s first install the required dependency before adding custom PPAs.

$ sudo apt install software-properties-common -y

Proceed to add the deadsnakes PPA to the APT package manager sources list using the command below.

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

Once done we can go ahead and install the packages using the following command:

$ sudo apt install python3.10

Verify your Python 3.10 installation by checking its version:

$ python3 -V

Method 2: Install Python 3.10 on Ubuntu 22.04 from Source

The other alternative to installing any version of Python on Ubuntu systems is from the Source code. This is our recommended way even though it requires more steps than the apt method above.

As always, make sure your system is up-to-date with the latest packages.

$ sudo apt update && sudo apt upgrade -y

Install the required prerequisite packages for the compilation of the Python source code using this command.

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

Now you need to visit the Python Downloads page and copy the link address of the Python 3.10.04 gzipped source tarball. Use the wget command to download it:

Visit the official Python site and download the latest stable release source package (Python 3.10.6).

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

Next, extract the archive file on your system.

$ tar xzf Python-3.10.6.tgz

Navigate to the extracted directory:

$ cd Python-3.10.6/

configure the Python source code before compiling it on your system.

$ ./configure --enable-optimizations

Finally, run the make command to compile and install Python 3.10 on Ubuntu. Optionally you can opt to use more CPU cores to fasted the build time. Run the following command to confirm the number of cores on your system.

$ nproc 

Run make to build Python 3.10 with the desired number of cores with the command below where -j 2 is the number of cores:

$ make -j 2
$ sudo make altinstall

The altinstall use here prevents the compiler from overriding the default Python versions.

You can confirm the installation by checking the Python version using this command.

$ python3 --version
Python 3.10.6

That’s It

You have now learned how to compile and install Python 3.10 on Ubuntu 22.04 systems using source code. Happy coding!

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.