×

How to Install Python 3 on RHEL 9 (Red Hat Enterprise Linux)

How to Install Python 3 on RHEL 9 (Red Hat Enterprise Linux)


In this blog post, we will learn how to install python 3 on RHEL 9 (Red Hat Enterprise Linux).

Python is a free and open-source programming language widely used in various domains, from web development to the data science. Python 3 comes with lot of modern features and extensive libraries.

Prerequisites

  • Pre-Installed RHEL 9 Instance
  • Red Hat Subscription or Locally Configured package repositories
  • Local user with sudo rights
  • Internet Connectivity

Python 3 can be installed using the methods like yum (or dnf) from default package repositories and from the source. We will cover both the methods in this post.

Install Python 3 on RHEL 9 using dnf (or yum) command

Python 3 and its dependencies are available in the default RHEL 9 repositories. At the time of writing this post, latest and stable version of python 3.12 was available.

Login to your RHEL 9 system and run the following commands from the terminal to install python 3.12.

$ sudo dnf repolist
$ sudo dnf install python3.12 -y

Once installed successfully verify the python version by running command.

$ python3.12 --version
Python 3.12.1
$

It is always recommended to install python-pip package as well. It will allow us to install python modules.

 $ sudo dnf install python3.12-pip -y

Install Python 3.12 Pip Using DNF Command

Next, try to install boto package using the beneath command,

$ pip3.12 install boto

Install Boto Package Python 3.12 RHEL 9

Output above confirms that boto package has been installed successfully. Now, move to the next method.

Installing Python 3 from the Source

In order to install python 3 from the source first we need to install Development tools. Run following dnf command.

$ sudo dnf groupinstall "Development Tools" -y

Install Development Tools for Python 3.12 on RHEL 9

Also install the other required dependencies using the following command.

$ sudo dnf install wget openssl-devel bzip2-devel libffi-devel -y

Once all the dependencies are installed, go to https://www.python.org/downloads/ and select Linux/UNIX and then download the latest version of python as shown below:

Gzipped Source Tarball Python

Alternate way to download latest python is via wget command. (Right click on above highlight link and then copy the link address)

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

Download Python 3.12.5 Tar File RHEL 9

Extract the downloaded file using tar command.

$ tar -xpvf Python-3.12.5.tgz

Go to the extracted folder,

$ cd Python-3.12.5

Next, run following commands one after the another,

$ ./configure --enable-optimizations
$ sudo make altinstall
$ sudo cp /usr/local/bin/python3.12 /usr/bin/
$ sudo cp /usr/local/bin/pip3.12 /usr/bin/

After the successful installation, verify the python version, run

$ python3.12 --version
Python 3.12.5
$

Next, try to install pandas package using the command,

$ pip3.12 install pandas

Install Pandas Package Pip 3.12 RHEL 9

Above output shows that pandas package has been installed successfully using pip3.12.

Switching Python Versions

If you have multiple python versions installed on your system then you can switch between them using ‘alternatives‘ command. In my case, I have Python 3.9.18 and 3.12.5 installed, let’s first set the python alternative (or add pythons to the alternative system). Run the beneath command.

$ sudo alternatives --install /usr/bin/python python /usr/bin/python3.12 10
$ sudo alternatives --install /usr/bin/python python /usr/bin/python3.9 20

Add Pythons Alternative System RHEL 9

Now to switch Python versions, use the following command:

$ sudo alternatives --config python

Switch Python Version Using Alternative RHEL 9

That’s all from this post, I hope you have found it informative and useful. Feel free to post your queries and feedback in below comments section.



Source link