In this guide, we intend to teach you How To Install Python 3.10 on Ubuntu 22.04.
Python is a popular general-purpose programming language that can be used for a wide variety of applications. It includes high-level data structures, dynamic typing, dynamic binding, and many more features that make it as useful for complex application development as it is for scripting or “glue code” that connects components together.
It can also be extended to make system calls to almost all operating systems and to run code written in C or C++. Due to its ubiquity and ability to run on nearly every system architecture, Python is a universal language found in a variety of different applications.
How To Install Python 3.10 on Ubuntu 22.04
Before you start to set up Python 3.10, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Ubuntu 22.04.
Now follow the steps below to install Python 3.10.4 Latest version on Ubuntu 22.04.
Install Python 3.10 on Ubuntu 22.04 from APT Repository
The first way to install Python 3.10 on Ubuntu 22.04 is to use 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
Next, use the following command to add the PPA deadsnake to the APT repository:
sudo add-apt-repository ppa:deadsnakes/ppa
At this point, you can install Python 3.10 on Ubuntu 22.04 with the following command:
sudo apt install python3.10
You can verify your Python 3.10 installation by checking its version:
Install Python 3.10 on Ubuntu 22.04 from the Source
Another way to install Python 3.10 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
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:
When your download is completed, extract your downloaded file with the following command:
tar -xf Python-3.10.*.tgz
Switch to your extracted directory:
Next, run the configure script to check the required dependencies:
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:
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.10 on Ubuntu 22.04:
sudo make altinstall
Verify your Python 3.10 installation by checking its version:
Output Python 3.10.4
How To Use Python 3.10
At this point, we want to create a test virtual environment to see that Python 3.10 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 it test_app:
python3.10 -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.10-dev python3.10-venv -y
Next, activate your virtual environment:
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.10 should be installed, which is the most used package manager for Python.
Check for the PIP upgrades:
python3.10 -m pip install --upgrade pip
For example, you can install Apache-Airflow with the command below:
pip3.10 install apache-airflow
To remove the application you can use the following command:
pip3.10 uninstall apache-airflow
To exit the virtual environment, use the following command:
At this point, you learn to install Python 3.10 on Ubuntu 2.04.
Hope you enjoy it.
You may be interested in these articles from the orcacore website: