AlmaLinuxRHEL Based

How To Install Pyenv on AlmaLinux 9

Install Pyenv on AlmaLinux 9

In this tutorial, we will show you how to install Pyenv on AlmaLinux 9. Python has become one of the most popular programming languages in recent years, with a wide range of applications in web development, data analysis, machine learning, and more. As a developer, managing multiple Python versions can be a challenging task, especially when working on projects with different requirements. This is where Pyenv comes in – a powerful tool that simplifies the management of Python versions on your system.

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 Pyenv 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.
  • You’ll need root or sudo privileges to install SDKMAN and make system-wide changes. Make sure you have the necessary permissions before starting the installation process.

Install Pyenv on AlmaLinux 9

Step 1. Update Your System.

It’s always a good practice to keep your system up-to-date with the latest packages and security patches. Open your terminal and run the following commands to update your AlmaLinux 9 system:

sudo dnf clean all
sudo dnf update

These commands will fetch the latest package information and upgrade any outdated packages to their latest versions.

Step 2. Installing Required Dependencies.

Pyenv relies on several dependencies to function properly. Before installing Pyenv, we need to install these dependencies using the AlmaLinux package manager, DNF. Development Tools:

First, we’ll install the necessary development tools by running the following command:

sudo dnf groupinstall "Development Tools"

Next, we’ll install additional libraries required by Pyenv and Python:

sudo dnf install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel xz-devel

Step 3. Installing Pyenv.

Now that we have the prerequisites in place, let’s proceed with installing Pyenv on AlmaLinux 9. There are two primary methods to install Pyenv: using the Pyenv installer script or manually cloning the Pyenv repository from GitHub. We’ll cover both methods below.

  • Method 1: Using the Pyenv Installer Script

The easiest way to install Pyenv is by using the official Pyenv installer script. Run the following command in your terminal:

curl https://pyenv.run | bash

This command will download and execute the Pyenv installer script, which will clone the Pyenv repository and set up the necessary environment variables.

  • Method 2: Manual Installation

Alternatively, you can install Pyenv manually by following these steps:

Clone the Pyenv repository from GitHub:

git clone https://github.com/pyenv/pyenv.git ~/.pyenv

Define the PYENV_ROOT environment variable:

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc

Add $PYENV_ROOT/bin to your PATH:

echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc

Restart your shell or source the .bashrc file:

source ~/.bashrc

Both methods will install Pyenv and make it available for use in your AlmaLinux 9 system.

Step 4. Configure Shell for Pyenv.

To ensure that Pyenv functions correctly, we need to configure our shell to recognize and initialize Pyenv. The steps may vary slightly depending on the shell you are using (e.g., Bash or Zsh).

Bash Configuration:

If you are using Bash, open your ~/.bashrc file in a text editor and add the following lines at the end:

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

Zsh Configuration:

If you are using Zsh, open your ~/.zshrc file in a text editor and add the following lines at the end:

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

After modifying the shell configuration file, restart your shell or source the configuration file to apply the changes:

source ~/.bashrc # For Bash
source ~/.zshrc # For Zsh

To verify that Pyenv is installed correctly, run the following command in your terminal:

pyenv --version

If the installation was successful, you should see the version number of Pyenv printed on the screen.

Congratulations! You have successfully installed Pyenv. Thanks for using this tutorial for installing the Pyenv on your AlmaLinux 9 system. For additional help or useful information, we recommend you check the official Pyenv 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 an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button