Tutorial

Easily install Python 3.10 on Ubuntu 22.04

5 min read

Python has long been a staple in the programming community due to its readability, versatility, and extensive library support. Python 3.10 continues this legacy by introducing several new features and improvements that enhance both the language and the development experience.

Notable additions include structural pattern matching, which brings a more readable and powerful way to handle complex data structures, and performance optimizations that make Python code run faster than ever.

Ubuntu 22.04, a popular Linux distribution known for its stability and user-friendly environment, is an excellent platform for running Python.

Whether you are a developer, data scientist, or hobbyist, having the latest version of Python on your Ubuntu system ensures you can take full advantage of the newest features and improvements.

This guide will walk you through the steps to install Python 3.10 on Ubuntu 22.04, ensuring you are set up to start coding with the latest tools.

Prerequisites for installing Python 3.10 on Ubuntu 22.04

Before installing Python 3.10 on Ubuntu 22.04, it is essential to ensure that a few prerequisites are met.

These prerequisites will help facilitate a smooth installation process.

First, you must have a system running Ubuntu 22.04.

Ubuntu 22.04, known for its stability and user-friendly interface, is a popular choice for both beginners and experienced Linux users.

Having this distribution installed ensures compatibility with the steps provided in this guide.

Additionally, administrative privileges (sudo access) are required.

Sudo access allows you to execute commands with superuser privileges, which are necessary for installing software and making system-wide changes. If you are the system administrator or have been granted sudo access by the administrator, you can proceed with the installation process.

Method 1: Using the deadsnakes PPA

One of the most convenient ways to install Python 3.10 on Ubuntu 22.04 is by using the deadsnakes PPA (Personal Package Archive).

This PPA provides newer Python versions that are not available in the default Ubuntu repositories.

Here is a step-by-step guide to adding the deadsnakes PPA and installing Python 3.10.

First, you need to add the deadsnakes PPA to your APT sources list. Open a terminal and run the following command:

sudo add-apt-repository ppa:deadsnakes/ppa

sudo add-apt-repository ppa:deadsnakes/ppa

This command adds the deadsnakes PPA repository to your system, allowing you to access and install the latest Python versions maintained by the deadsnakes team.

Next, update your package list to include the new repository by running:

sudo apt update

sudo apt update

This command refreshes your package list, ensuring that the latest packages from the deadsnakes PPA are included.

Finally, install Python 3.10 by executing:

sudo apt install python3.10

sudo apt install python3.10

This command installs Python 3.10 on your system.

Once the installation is complete, you can verify that Python 3.10 has been installed correctly by running:

python3.10 --version

python3.10 --version

If the installation is successful, this command will output the version number of Python 3.10, confirming that it has been installed and is ready for use.

Using the deadsnakes PPA is a straightforward and reliable method to install Python 3.10 on Ubuntu 22.04, especially for users who prefer a quick and hassle-free installation process.

Method 2: Manual Installation of Python 3.10 on Ubuntu 22.04 from Source Code

For users who prefer a more hands-on approach, building Python 3.10 from source is an option.

This method provides a deeper understanding of the installation process and allows for customization, but it is more advanced and not recommended for beginners due to its complexity.

Here’s a brief overview of the steps involved.

First, you need to ensure that your system has the necessary build dependencies.

Open a terminal and run the following commands to install them:

sudo apt update
sudo apt install build-essential checkinstall
sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-devlibbz2-dev libffi-dev zlib1g-dev

sudo apt update sudo apt install build-essential checkinstall sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev

These commands install various development libraries and tools required to compile Python from source.

Next, download the Python 3.10 source code from the official Python website.

You can do this using the wget command:

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

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

Once the download is complete, extract the tarball:

tar -xf Python-3.10.0.tgz

tar -xf Python-3.10.0.tgz

Navigate to the extracted directory:

cd Python-3.10.0

cd Python-3.10.0

Now, configure the build environment. This step checks your system for the necessary dependencies and prepares the source code for compilation:

./configure --enable-optimizations

./configure --enable-optimizations

The --enable-optimizations flag ensures that the resulting Python build is optimized for performance.

Next, compile the source code using the make command.

This step can take some time, depending on your system’s performance:

make -j 4

make -j 4

The -j 4 flag specifies that the build process should use 4 CPU cores.

Adjust this number based on the number of cores available on your system.

Finally, install the newly compiled Python version:

sudo make altinstall

sudo make altinstall

The altinstall target is used instead of install to avoid overwriting the default system Python.

Verification Python 3.10 is installed on Ubuntu 22.04

After installing Python 3.10 using either method, it is crucial to verify that the installation was successful.

This ensures that Python is correctly set up and ready for use.

To verify the installation, open a terminal and run the following command:

python3.10 --version

python3.10 --version

If Python 3.10 is installed correctly, you should see an output similar to:

Python 3.10.0

This output confirms that Python 3.10 is installed and accessible from the terminal.

You can now begin using Python 3.10 for your development projects, taking advantage of its new features and improvements.

Conclusion

In this guide, we explored two methods for installing Python 3.10 on Ubuntu 22.04: using the deadsnakes PPA and manual installation from source code.

Each method has its own advantages, with the PPA offering a quick and straightforward installation process, while the manual method provides a deeper, more customizable setup experience.

To recap, the deadsnakes PPA method involves adding the PPA to your APT sources list, updating the package list, and installing Python 3.10.

This method is user-friendly and recommended for most users. On the other hand, the manual installation method requires downloading the source code, installing dependencies, and compiling Python from scratch.

This method is more suitable for advanced users who need a custom build or want to understand the installation process in detail.

Regardless of the method you choose, installing Python 3.10 on Ubuntu 22.04 equips you with the latest features and performance enhancements of Python, enabling you to write more efficient and powerful code.

Now that you have Python 3.10 installed, you can dive into exploring its new features and start coding. Whether you’re developing web applications, analyzing data, or automating tasks, Python 3.10 provides the tools and capabilities to help you succeed.

Happy coding!