How to Install Python 3.10 on AlmaLinux 9

Python is an interpreted high-level general-purpose programming language. Its design philosophy emphasizes code readability with its use of significant indentation. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects.

Prerequisites

  • A system with AlmaLinux 9 installed and running.

  • Have root access to the system.

  • To install the Python from the source code, you will need additional packages such as GCC compiler and other dependencies installed. Run the below command to install them.

    dnf install wget yum-utils make gcc openssl-devel bzip2-devel libffi-devel zlib-devel 

Update your System.

dnf update 

Install Python 3.10.5

At the time of writing this article, the latest version of Python available was 3.10.5.

The first step is to download the source code of Python 3.10.5. Check the latest version that is available by visiting the official site https://www.python.org/downloads/

Now, Let us download the source code by using wget as shown below,

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

Output:

[root@server ~]# wget https://www.python.org/ftp/python/3.10.5/Python-3.10.5.tgz
--2022-06-09 17:07:59--  https://www.python.org/ftp/python/3.10.5/Python-3.10.5.tgz
Resolving www.python.org (www.python.org)... 151.101.36.223, 2a04:4e42:9::223
Connecting to www.python.org (www.python.org)|151.101.36.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25628472 (24M) [application/octet-stream]
Saving to: ‘Python-3.10.5.tgz’

Python-3.10.5.tgz 100%[===================>]  24.44M  48.9MB/s    in 0.5s

2022-06-09 17:07:59 (48.9 MB/s) - ‘Python-3.10.5.tgz’ saved [25628472/25628472]

Extract the file by using the below command,

tar xzf Python-3.10.5.tgz 

After extracting the file, Change the directory to Python-3.10.5. Then apply the source code with the required values using the command below.

cd Python-3.10.5

./configure --with-system-ffi --with-computed-gotos --enable-loadable-sqlite-extensions 

Next, we compile the source code with make. Here nproc will provide the number of CPU cores available using the command below.

make -j ${nproc} 
make altinstall 

Once the installation is complete, Check the Python version using the following command.

python3.10 -V 

Output:

[root@server Python-3.10.5]# python3.10 -V
Python 3.10.5
[root@server Python-3.10.5]#

Create Virtual Environment

Create Virtual Environment and activate using the below command.

/usr/local/bin/python3.10 -m venv appenv

source appenv/bin/activate

Output:

[root@server Python-3.10.5]# sudo /usr/local/bin/python3.10 -m venv appenv
[root@server Python-3.10.5]# source appenv/bin/activate
(appenv) [root@server Python-3.10.5]#

In this virtual Environment, you will be able to use the latest version of Python that was installed now. You can verify the version by running the command: python -V.

And to exit the Virtual Environment, you can use the below command,

deactivate

This concludes the installation of the latest Python version on AlmaLinux.