How To Install Python 3.11 on Ubuntu 22.04

This guide intends to teach you How To Install Python 3.11 on Ubuntu 22.04.

Python is a high-level programming language. It has since been released under an open-source license, making it freely available to anyone who’d like to use or modify the software.

Python is known for its ease of use, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C++ or Java.

Python 3.11 is the newest release of the Python programming language, and it contains many new features and optimizations.

Steps To Install Python 3.11 on Ubuntu 22.04

To complete this guide, you must log in to your server as a root or non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Ubuntu 22.04.

Now follow the steps below to install Python 3.11 Latest version on Ubuntu 22.04 in two different ways:

  1. From APT Repository
  2. From the Source

Install Python 3.11 on Ubuntu 22.04

The first way to install Python 3.11 on Ubuntu 22.04 is to use the APT repository.

Set up Python on Ubuntu from the APT repository

First, update your local package index with the following command:

sudo apt update

Then, you need to install the dependencies for adding the PPA repository:

sudo apt install software-properties-common -y
Add PPA Repository

Next, use the following command to add the PPA dead snake to the APT repository:

sudo add-apt-repository ppa:deadsnakes/ppa

At this point, you can install Python 3.11 on Ubuntu 22.04 with the following command:

sudo apt install python3.11

You can verify your Python 3.11 installation by checking its version:

python3.11 --version
Output
Python 3.11.1

Set up Python 3.11 on Ubuntu from the Source

Another way to install Python 3.11 on your server, is to build from the source code. It’s recommended to use this way than the APT repository.

First, update your local package index with the following command:

sudo apt update

Then, install the dependencies with the command below:

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

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

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

When your download is completed, extract your downloaded file with the following command:

sudo tar -xf Python-3.11.*.tgz

Switch to your extracted directory:

cd Python-3.11.*/
Build and Install Python 3.11

Next, run the configure script to check the required dependencies:

./configure --enable-optimizations

At this point, you can start your build process with the make command. But before this, you need to check the number of your cores with the command below:

nproc

Example output:

Output
2

Then, build your process with the command below:

make -j 2

Note: The (-j) corresponds to the number of cores in your system to speed up the build time.

When your build process is completed, use the following command to install Python 3.11 on Ubuntu 22.04:

sudo make altinstall

Verify your Python 3.11 installation by checking its version:

python3.11 --version
Output
Python 3.11.1

Create a Test Virtual Environment with Python 3.11

At this point, we want to create a test virtual environment to see that Python 3.11 is working correctly on Ubuntu 22.04.

First, create a project directory and switch to it with the command below:

mkdir ~/test_app && cd ~/test_app

Then, create a virtual environment with the following command, for the test name test_app_venv:

python3.11 -m venv test_app_venv

Note: The compiled installation included venv. However, if you installed using the APT package manager method, you may need to install the venv package if you encounter problems.

sudo apt install python3.11-dev python3.11-venv -y

Next, activate your virtual environment:

source test_app_venv/bin/activate

After starting the virtual environment, you will now be in the shell prompt terminal. You will notice the name of your environment will be prefixed.

By default, PIP3.11 should be installed, which is the most used package manager for Python.

Check for the PIP upgrades:

python3.11 -m pip install --upgrade pip

For example, you can install Apache-Airflow with the command below:

pip3.11 install apache-airflow

To remove the application you can use the following command:

pip3.11 uninstall apache-airflow

To exit the virtual environment, use the following command:

deactivate

Conclusion

At this point, you have learned to Install Python 3.11 on Ubuntu 22.04.

Hope you enjoy it.

You may be like these articles:

How To Install Siege on Ubuntu 22.04

Upgrade Linux Kernel on Ubuntu 22.04

Install PostgreSQL 15 on Ubuntu 22.04

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!