How To Install Python 3.11 on AlmaLinux 8 with Easy Steps

Posted on

How To Install Python 3.11 on AlmaLinux 8 with Easy Steps

How To Install Python 3.11 on AlmaLinux 8 with Easy Steps

Python has cemented its place as one of the most popular and versatile programming languages in the world. Its clear syntax, extensive libraries, and large community support make it ideal for everything from web development to data science and system administration. If you’re using AlmaLinux 8, you’ll likely need a specific version of Python for your projects. This guide will walk you through How To Install Python 3.11 on AlmaLinux 8 step-by-step. We’ll also explore alternative installation methods.

Python is a high-level, interpreted, interactive, and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where other languages use punctuation, and it has fewer syntactical constructions than other languages.

At the moment, the latest version of Python is 3.13. You can check for the installation steps in this guide on Python 3.13 Setup on AlmaLinux.

You can now follow the steps below on the Orcacore website to get Python 3.11 on AlmaLinux 8.

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

Set up Python 3.11 on AlmaLinux 8

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

sudo dnf update -y

Install Dependencies

Then, install the required packages and dependencies on your server with the command below:

sudo dnf install gcc openssl-devel bzip2-devel libffi-devel zlib-devel wget make tar -y

Download Python 3.11

Now you need to visit the Python Downloads page to check the latest stable version and download it with the following wget command:

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

Extract your downloaded file with the following command:

sudo tar -xf Python-3.11.1.tgz

Next, switch to your source directory:

cd Python-3.11.1

Run Configuration Script

At this point, you need to run the configuration script to be sure that all dependencies are ready for the Python 3.11 installation to work on AlmaLinux 8:

./configure --enable-optimizations

The –enable-optimizations option is for use after all debugging and maximum performance with minimum run-time checks is required.

Build and Install Python 3.11

After the configuration script is completed, you need to start your build process with the following command:

make -j 2

The -j option is related to the number of cores in your system to speed up the build time.

To find how many cores you have on your system, you can use the following command:

nproc

The build process takes some time to complete.

When it is finished, you can install the Python 3.11 source on AlmaLinux 8 with the following command:

sudo make altinstall

When your installation is completed, you can verify your Python 3.11 installation on AlmaLinux 8 by checking its version:

python3.11 --version
Python 3.11 AlmaLinux 8

To ensure that Python 3.11 is working correctly on AlmaLinux 8, you can create a test Python project.

Create a Test Python project on AlmaLinux 8

First, you need to create the Python project directory and switch to it with the following command:

mkdir ~/test_app && cd ~/test_app

Then, from the project directory, create a virtual environment with the following command, here we named it test_app_venv:

python3.11 -m venv test_app_venv

Next, activate your virtual environment with the command below:

source test_app_venv/bin/activate

You will see that your shell prompts changes to the name of your virtual environment.

For example, you can install Apache-Airflow inside your virtual environment with the pip package manager for Python:

pip install apache-airflow

To exit from your virtual environment you can use the following command:

deactivate

Conclusion

At this point, you have learned to install Python 3.11 on AlmaLinux 8 and create a test Python project to verify that your Python 3.11 is working correctly on your server.

Hope you enjoy it. You may also like these articles:

How To Install Python 3.11 on Centos 7

How To Install Python on Windows 10

Top 5 Remote Desktop Solutions for Linux in 2025

Key Features and Improvements of Linux kernel 6.14

Alternative Installation Methods for Python 3.11 on AlmaLinux 8

While the method described above involving downloading the source code and building it is a reliable way to install Python 3.11, it can be time-consuming and requires compiling software. Here are two alternative methods that can be easier and faster:

1. Using conda (Anaconda or Miniconda)

Anaconda and Miniconda are popular package, dependency, and environment management systems specifically designed for data science and machine learning. However, they’re also excellent for managing different Python versions. Miniconda is a lightweight version of Anaconda that only includes conda and its dependencies. It’s often preferred if you don’t need all the pre-installed packages that come with Anaconda.

Steps:

  1. Download Miniconda:

    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

    (Make sure to download the latest version. Check the Anaconda website for the most up-to-date link.)

  2. Install Miniconda:

    bash Miniconda3-latest-Linux-x86_64.sh

    Follow the prompts during the installation. It’s recommended to accept the default installation location. You’ll also be asked if you want to initialize conda in your .bashrc. It’s generally a good idea to say yes, as this will automatically activate the base conda environment when you open a new terminal.

  3. Create a Conda Environment with Python 3.11:

    conda create -n py311 python=3.11

    This command creates a new conda environment named py311 and installs Python 3.11 into it.

  4. Activate the Environment:

    conda activate py311

    Now, your terminal will show (py311) at the beginning of the prompt, indicating that the py311 environment is active.

  5. Verify the Python Version:

    python --version

    This should output Python 3.11.x (or similar), confirming that Python 3.11 is active in your environment.

Code Example (within the Conda environment):

Create a simple Python script hello.py:

print("Hello from Python 3.11 in Conda!")

Run the script:

python hello.py

Explanation:

Conda provides isolated environments. This means that Python packages and dependencies installed within the py311 environment won’t interfere with the system’s default Python installation or other conda environments. This is extremely useful for managing dependencies and avoiding conflicts between different projects.

2. Using pyenv

pyenv is a tool that allows you to easily switch between multiple Python versions. It doesn’t install Python itself; instead, it manages installations performed by other tools or by you directly. It’s a lightweight and flexible option.

Steps:

  1. Install pyenv and Dependencies:

    First, install the necessary dependencies:

    sudo dnf install -y git gcc make patch openssl-devel bzip2-devel libffi-devel zlib-devel readline-devel sqlite-devel

    Then, install pyenv using the pyenv-installer:

    curl https://pyenv.run | bash
  2. Configure Shell for pyenv:

    Add the following lines to your .bashrc or .zshrc file (depending on your shell):

    export PYENV_ROOT="$HOME/.pyenv"
    export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init -)"

    Source your shell configuration file:

    source ~/.bashrc  # or source ~/.zshrc
  3. Install Python 3.11 with pyenv:

    pyenv install 3.11.1  # Replace 3.11.1 with the specific version you want

    This downloads and installs Python 3.11.1. It might take some time.

  4. Set Python 3.11 as the Local Python Version:

    pyenv local 3.11.1

    This sets Python 3.11.1 as the version to use in the current directory. pyenv also supports global versions (for system-wide defaults) and shell-specific versions.

  5. Verify the Python Version:

    python --version

    This should output Python 3.11.1 (or similar).

Code Example (within the pyenv managed environment):

Create a simple Python script pyenv_test.py:

import sys
print(f"Python version: {sys.version}")

Run the script:

python pyenv_test.py

Explanation:

pyenv allows you to easily switch between different Python versions on a per-project or global basis. The pyenv local command creates a .python-version file in the current directory. pyenv reads this file to determine which Python version to use. This is a clean and effective way to manage different Python versions for different projects without conflicts.

In summary, while building from source provides granular control, conda and pyenv offer more streamlined and convenient ways to install Python 3.11 on AlmaLinux 8, especially when dealing with multiple projects and varying Python version requirements. Choose the method that best fits your workflow and project needs.

Leave a Reply

Your email address will not be published. Required fields are marked *