CentLinux | Learn How to Install CentOS/Rocky Linux Servers

Monday, May 2, 2022

Install Multiple Python versions on Rocky Linux 8

Install Multiple Python Versions on Rocky Linux 8

In this article, you will learn how to install multiple Python versions on Rocky Linux 8 or other RPM based distros.

 

Table of Contents:

 

What is Python? :

Python is a high-level, interpreted, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation.

Python is dynamically-typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly procedural), object-oriented and functional programming. It is often described as a "batteries included" language due to its comprehensive standard library.

Guido van Rossum began working on Python in the late 1980s as a successor to the ABC programming language and first released it in 1991 as Python 0.9.0. Python 2.0 was released in 2000 and introduced new features such as list comprehensions, cycle-detecting garbage collection, reference counting, and Unicode support. Python 3.0, released in 2008, was a major revision that is not completely backward-compatible with earlier versions. Python 2 was discontinued with version 2.7.18 in 2020.

Python consistently ranks as one of the most popular programming languages. (Source: Wikipedia)

If you want to develop some amazing projects in Python Proramming Language, then you should start with Python Crash Course, 2nd Edition written by Eric Matthes.

Or you can buy an online course such as Complete Python Tutorial for Beginners to speedup your learning process.

Install Multiple Python Versions on Rocky Linux 8

Environment Specification:

We are using a minimal Rocky Linux 8 virtual machine with following specifications.

  • CPU - 3.4 Ghz (2 cores)
  • Memory - 2 GB
  • Storage - 20 GB
  • Operating System - Rocky Linux 8.5 (Green Obsidian)
  • Hostname – python-01.centlinux.com
  • IP Address - 192.168.116.128 /24

 

Update your Rocky Linux Server:

By using a SSH client software, login to python-01.centlinux.com as root user.

Rebuild cache of installed yum repositories.

# dnf makecache
MariaDB                                         1.5 kB/s | 3.4 kB     00:02
Rocky Linux 8 - AppStream                       434 kB/s | 9.7 MB     00:22
Rocky Linux 8 - BaseOS                          647 kB/s | 6.8 MB     00:10
Rocky Linux 8 - Extras                          3.6 kB/s |  12 kB     00:03
Metadata cache created.

Execute following command to update your Rocky Linux server.

# dnf update -y
Last metadata expiration check: 0:00:59 ago on Thu 30 Apr 2022 11:40:04 PM PKT.
Dependencies resolved.
Nothing to do.
Complete!

Check the Linux Operating System and Linux Kernel versions as follows.

# uname -r
4.18.0-348.20.1.el8_5.x86_64

# cat /etc/os-release
NAME="Rocky Linux"
VERSION="8.5 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.5"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.5 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8:GA"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
ROCKY_SUPPORT_PRODUCT="Rocky Linux"
ROCKY_SUPPORT_PRODUCT_VERSION="8"

 

Installing Python3 on Rocky Linux:

List down the available Python versions in your standard yum repositories.

# dnf search python | grep ^python | grep nterpre
Last metadata expiration check: 2:12:22 ago on Sun 01 May 2022 09:51:56 PM PKT.
python36.x86_64 : Interpreter of the Python programming language
python38.x86_64 : Interpreter of the Python programming language
python39.x86_64 : Version 3.9 of the Python interpreter
python2.x86_64 : An interpreted, interactive, object-oriented programming language

Here, the latest available version of Python programming language is 3.9.

Let's install Python 3.9 by executing dnf command.

# dnf install -y python39

After successful installation, verify the version of Python by using following command.

# python3 -V
Python 3.9.6

 

Installing Python2 on Rocky Linux:

Similarly, install Python2 on your Linux server.

# dnf install -y python2

After installation, verify the version of Python as follows.

# python2 -V
Python 2.7.18

 

Using Multiple Python Versions on Rocky Linux:

Linux provides alternatives command to configure and use multiple Python versions on a same operating system.

Execute following command to configure your preferred Python version.

# alternatives --config python

There are 4 programs which provide 'python'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/libexec/no-python
   2           /usr/bin/python3
   3           /usr/bin/python3.9
   4           /usr/bin/python2

Enter to keep the current selection[+], or type selection number: 2

Now, execute the python command to check active Python version.

# python -V
Python 3.9.6

Again use the alternatives command to switch to another version of Python programming language.

# alternatives --config python

There are 4 programs which provide 'python'.

  Selection    Command
----------------------------------------------- 
*  1           /usr/libexec/no-python
 + 2           /usr/bin/python3
   3           /usr/bin/python3.9
   4           /usr/bin/python2

Enter to keep the current selection[+], or type selection number: 4

Again check the active Python version.

# python -V
Python 2.7.18

You can see that, now Python 2.7 is active version on your Linux server.

 

Conclusion:

In this article, you have learned how to install multiple Python versions on Rocky Linux 8 or other RPM based distros.

If you find this article useful? Consider supporting us by Buy Me A Coffee


© 2023 CentLinux. All Rights Reserved.