Python has become one of the world’s most popular programming languages. It is a programming language that is quite easy for beginners to learn, making it one of the most popular programming languages nowadays. The latest version of Python brings a variety of new features and significant performance improvements. In this article, we will show you how to install Python on AlmaLinux 10.
Table of Contents
Prerequisites
- An AlmaLinux 10 VPS
- SSH root access or a user with sudo privileges is required
Conventions
# given commands should be executed with root privileges either directly as a root user or by use of sudo command
$ given commands should be executed as a regular user
Log in to VPS and Update the System
First of all, we need to log in to our Debian 12 VPS through SSH:
ssh root@IP_Address -p Port_number
If you do not have direct root access, you can replace “root” with a user that has sudo privileges. Additionally, replace “IP_Address” and “Port_Number” with your server’s respective IP address and SSH port number. Next, let’s make sure that we’re on AlmaLinux 10.
# cat /etc/almalinux-release
The command should return an output similar to this:
AlmaLinux release 10.0 (Purple Lion)
Install Python from Source
By default, Python 3.12 is installed on AlmaLinux 10. If you want to install another version of Python, we can install it from the source.
This method provides complete control over Python configuration and usually results in optimal performance. To compile Python from source code, we need development tools. Install the following essential packages; these packages are also required when we install Python using the pyenv tool:
# dnf groupinstall "Development Tools" -y
# dnf install gcc openssl-devel bzip2-devel libffi-devel zlib-devel sqlite-devel ncurses-devel readline-devel -y
Next, we can download the source from their download page at https://www.python.org/downloads/
# cd /tmp
# wget https://www.python.org/ftp/python/3.13.5/Python-3.13.5.tgz
Once the download is complete, let’s extract the file:
# tar -xzvf Python-3.13.5.tgz
# cd Python-3.13.5
Configure Python build with optimizations:
# ./configure --enable-optimizations --prefix=/usr/local
The –enable-optimizations flag will make Python run faster, although the compilation process will take longer.
Start the compilation process:
# make -j $(nproc)
The $(nproc) command will use all available CPU cores to speed up the compilation process.
Finally, we can install the package.
# make altinstall
We use altinstall instead of install to avoid the installation process from overwriting the system’s default Python.
Install Python Using pyenv
Pyenv is a Python version management tool designed for macOS and Linux-based systems. With this tool, users can install, manage, and switch between multiple versions of Python on a single machine.
Before installing pyenv, we need to get the latest version of pyenv from GitHub. Let’s execute the command below.
# git clone https://github.com/pyenv/pyenv.git ~/.pyenv
Now, we need to edit our ~/.bashrc file
# nano ~/.bashrc
And add these lines to it.
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
Save the file, then exit from the editor. To apply the changes, we can source the file.
# source ~/.bashrc
At this point, we can use the pyenv tool. Let’s execute the command below to see the list of available Python versions to install.
# pyenv install -l
We have Python 3.12 on the system, and Python 3.13 installed using the source. Now, we are going to install another version. Let’s say we want to install Python 3.11. We can simply execute this command:
# pyenv install 3.11
It may take some time for the package to be installed. You need to wait until it finishes installing Python. The command above will print an output similar to this:
root@localhost:~# pyenv install 3.11
Downloading Python-3.11.13.tar.xz...
-> https://www.python.org/ftp/python/3.11.13/Python-3.11.13.tar.xz
Installing Python-3.11.13...
Installed Python-3.11.13 to /root/.pyenv/versions/3.11.13
Once completed, you can run this command to check the available version.
# pyenv versions
The command will print this message:
* system (set by /root/.pyenv/version)
3.11.13
As seen on your screen, Python 3.11.13 has been installed, but it’s not activated. Currently, the one listed there with an asterisk (*) is the active one. It indicates the currently active version and refers to the system-wide Python version. You can check the Python version with this command:
# python3 --version
The command will show you the active Python version, which is the one installed using the default AlmaLinux repository.
root@localhost:~# python3 --version
Python 3.12.9
To activate Python 3.11.13 globally, let’s run this command
# pyenv global 3.11.13
That’s it. Python 3.11.13 is active now. You can verify it by running the command
# python3 --version
It will return an output like this:
Python 3.11.13
Besides activating it globally, you can also use it locally. Use this command instead:
# pyenv local 3.11.13
You can also install a virtual environment when using pyenv. The command is similar to the one you usually use.
# python -m venv [VENV-NAME]
Congratulations
You have followed this article, and now you can install Python on AlmaLinux 10.
If you are one of our web hosting customers and use our managed AlmaLinux Hosting, you don’t have to follow this tutorial and install Python on AlmaLinux 10 yourself; our Linux admins will install Python hosting. They are available 24/7 and will take care of your request immediately. Simply submit a ticket.
PS. If you liked this post, please share it with your friends or simply leave a comment below. Thanks.