AlmaLinuxRHEL Based

How To Install Python on AlmaLinux 9

Install Python on AlmaLinux 9

In this tutorial, we will show you how to install Python on AlmaLinux 9. Python 3.12 is the latest major release of the Python programming language. It comes with several new features, optimizations, and library improvements.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Python programming language on AlmaLinux 9. You can follow the same instructions for CentOS and Rocky Linux or RHEL-based.

Prerequisites

  • A server running one of the following operating systems: AlmaLinux 9.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Python.
  • Python requires certain permissions that can only be granted to a superuser or a user with sudo privileges. Ensure that you have the necessary administrative access.

Install Python on AlmaLinux 9

Step 1. Before diving into the installation process, it’s crucial to ensure your system is up-to-date. This step helps avoid potential conflicts and ensures a smooth installation process. To update your system packages, open your terminal and type the following command:

sudo dnf clean all
sudo dnf update

Once the system is updated, we need to install some essential development tools and libraries. These tools are necessary for building and installing Python from source. Execute the following command to install the required packages:

sudo dnf install gcc openssl-devel bzip2-devel libffi-devel zlib-devel

Step 2. Installing Python 3.12.1 on AlmaLinux 9.

First, download the latest Python 3.12 source code tarball from the official website:

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

Verify the integrity of the downloaded file using SHA-256 checksum or GPG signature.

Next, extract the compressed tarball using the following command:

tar xzf Python-3.12.1.tgz

This will create a Python-3.12.1 directory. Navigate into it:

cd Python-3.12.1

Before compiling the source code, we need to run the configuration script. This script checks the system for all necessary dependencies and prepares the build environment. To run the configuration script with optimizations, use the following command:

./configure --enable-optimizations

 Next, compile the source code using the make command. The -j option allows you to specify the number of cores to use, speeding up the build process. For example, to use 4 cores, run:

make -j4

 Once the build process completes, install Python 3.12 using the make altinstall command:

sudo make altinstall

After the installation, it’s important to verify that Python 3.12 was installed correctly. To do this, check the Python version using the following command:

python3.12 --version

Step 3. Upgrade Pip and Install Modules.

Some Python modules may not be available yet for Python 3.12. So upgrade pip first:

python3.12 -m pip install --upgrade pip

Step 4. Setting Up a Python Virtual Environment.

Working within a virtual environment is a best practice in Python development. It isolates your Python projects and their dependencies, preventing conflicts between different project dependencies. To create a virtual environment for your Python 3.12.1 installation, use the venv module:

/usr/local/bin/python3.12.1 -m venv myenv

This command creates a new virtual environment named myenv. To activate the virtual environment, use the following command:

source myenv/bin/activate

With the virtual environment activated, you can now install and manage Python packages isolated from the system Python.

Congratulations! You have successfully installed Python. Thanks for using this tutorial for installing Python programming language on your AlmaLinux 9 system. For additional help or useful information, we recommend you check the official Python website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button