Install Python on Rocky Linux 8

|
Last Updated:
|
|

Follow through this guide to learn how to install Python on Rocky Linux 8. There exists different ways of installing Python on Linux systems. You can either install a specific version of Python from the source code or simply install the specific Python version from the specific Linux distro package repository.

Installing Python on Rocky Linux 8

As already mentioned, you can install Python by building from the source code or from the system package repositories.

Install Python 3.9 on Rocky Linux 8

As of this writing, the default Rocky Linux 8 AppStream repository provides Python 2, Python 3.6, 3.8, and 3.9.

To install Python 3.9 on Rocky Linux 8, run the command below;

dnf install python39

Dependencies resolved.
============================================================================================================================================================================
 Package                                        Architecture                Version                                                    Repository                      Size
============================================================================================================================================================================
Installing:
 python39                                       x86_64                      3.9.2-1.module+el8.4.0+574+843c4898                        appstream                       31 k
Installing dependencies:
 python39-libs                                  x86_64                      3.9.2-1.module+el8.4.0+574+843c4898                        appstream                      8.1 M
 python39-pip-wheel                             noarch                      20.2.4-3.module+el8.4.0+574+843c4898                       appstream                      1.3 M
 python39-setuptools-wheel                      noarch                      50.3.2-3.module+el8.4.0+574+843c4898                       appstream                      496 k
Installing weak dependencies:
 python39-pip                                   noarch                      20.2.4-3.module+el8.4.0+574+843c4898                       appstream                      2.0 M
 python39-setuptools                            noarch                      50.3.2-3.module+el8.4.0+574+843c4898                       appstream                      870 k
Enabling module streams:
 python39                                                                   3.9                                                                                            

Transaction Summary
============================================================================================================================================================================
Install  6 Packages

Total download size: 13 M
Installed size: 45 M
Is this ok [y/N]: y

Once installed, you can always counter check the installed version of Python, if you dont already have other versions installed;

python3 -V

Sample output;

Python 3.9.2

Install Python 3.8 on Rocky Linux 8

To install Python 3.8 simply execute the command below;

dnf install python38

Dependencies resolved.
============================================================================================================================================================================
 Package                                        Architecture                Version                                                    Repository                      Size
============================================================================================================================================================================
Installing:
 python38                                       x86_64                      3.8.6-3.module+el8.4.0+595+c96abaa2                        appstream                       78 k
Installing dependencies:
 python38-libs                                  x86_64                      3.8.6-3.module+el8.4.0+595+c96abaa2                        appstream                      8.3 M
 python38-pip-wheel                             noarch                      19.3.1-1.module+el8.4.0+570+c2eaf144                       appstream                      1.2 M
 python38-setuptools-wheel                      noarch                      41.6.0-4.module+el8.4.0+570+c2eaf144                       appstream                      303 k
Installing weak dependencies:
 python38-pip                                   noarch                      19.3.1-1.module+el8.4.0+570+c2eaf144                       appstream                      1.9 M
 python38-setuptools                            noarch                      41.6.0-4.module+el8.4.0+570+c2eaf144                       appstream                      666 k
Enabling module streams:
 python38                                                                   3.8                                                                                            

Transaction Summary
============================================================================================================================================================================
Install  6 Packages

Total download size: 12 M
Installed size: 45 M
Is this ok [y/N]: y

Install Python 3.6 on Rocky Linux 8

To install Python 3.6 simply execute the command below;

dnf install python36

Dependencies resolved.
============================================================================================================================================================================
 Package                                   Architecture                  Version                                                     Repository                        Size
============================================================================================================================================================================
Installing:
 python36                                  x86_64                        3.6.8-2.module+el8.4.0+597+ddf0ddea                         appstream                         18 k
Installing dependencies:
 python3-pip                               noarch                        9.0.3-19.el8.rocky                                          appstream                         19 k
 python3-setuptools                        noarch                        39.2.0-6.el8                                                baseos                           162 k
Enabling module streams:
 python36                                                                3.6                                                                                               

Transaction Summary
============================================================================================================================================================================
Install  3 Packages

Total download size: 198 k
Installed size: 466 k
Is this ok [y/N]: y

Install Python 2.7 on Rocky Linux 8

To install Python 2.7 simply execute the command below. Note that Python 2 is no longer supported.

dnf install python2

Dependencies resolved.
============================================================================================================================================================================
 Package                                       Architecture                Version                                                     Repository                      Size
============================================================================================================================================================================
Installing:
 python2                                       x86_64                      2.7.18-4.module+el8.4.0+403+9ae17a31                        appstream                      108 k
Installing dependencies:
 python2-libs                                  x86_64                      2.7.18-4.module+el8.4.0+403+9ae17a31                        appstream                      6.0 M
 python2-pip-wheel                             noarch                      9.0.3-18.module+el8.4.0+403+9ae17a31                        appstream                      1.0 M
 python2-setuptools-wheel                      noarch                      39.0.1-13.module+el8.4.0+403+9ae17a31                       appstream                      286 k
Installing weak dependencies:
 python2-pip                                   noarch                      9.0.3-18.module+el8.4.0+403+9ae17a31                        appstream                      1.7 M
 python2-setuptools                            noarch                      39.0.1-13.module+el8.4.0+403+9ae17a31                       appstream                      641 k
Enabling module streams:
 python27                                                                  2.7                                                                                             

Transaction Summary
============================================================================================================================================================================
Install  6 Packages

Total download size: 9.7 M
Installed size: 37 M
Is this ok [y/N]: y

Checking Python 2.x version;

python2 -V
Python 2.7.18

List All Available Python Versions

To list all available versions of Python, run the command below;

ls -alh1 /usr/bin/python*

lrwxrwxrwx. 1 root root    9 May 30 22:43 /usr/bin/python2 -> python2.7
-rwxr-xr-x. 1 root root 7.9K May 30 22:43 /usr/bin/python2.7
lrwxrwxrwx. 1 root root   25 Jul 16 11:53 /usr/bin/python3 -> /etc/alternatives/python3
lrwxrwxrwx. 1 root root   31 Jul  2 19:01 /usr/bin/python3.6 -> /usr/libexec/platform-python3.6
lrwxrwxrwx. 1 root root   32 Jul  2 19:01 /usr/bin/python3.6m -> /usr/libexec/platform-python3.6m
-rwxr-xr-x. 1 root root 7.6K Jun 30 00:16 /usr/bin/python3.8
-rwxr-xr-x. 1 root root 7.6K Jun 11 20:24 /usr/bin/python3.9

Setting Default Python Version

If you have multiple versions of Python installed, you can use alternatives command to set your default version of Python.

For example, you can run the command below to set your default version of Python.

update-alternatives --config python

Sample output;


There are 5 programs which provide 'python'.

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

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

Select enter specific number that defines the version of Python you want to set as the default version and press ENTER key. The + symbol shows the current default version.

In the above, option 2 was selected, which sets Python 3.6.8 as the default version;

python -V
Python 3.6.8

You can also use the command below to set default Python version.

alternatives --install <link> <name> <path> <priority>

For example;

update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1

You can list the alternatives;

update-alternatives --list

libnssckbi.so.x86_64	auto  	/usr/lib64/pkcs11/p11-kit-trust.so
python              	manual	/usr/bin/python3
ifup                	auto  	/usr/libexec/nm-ifup
cifs-idmap-plugin   	auto  	/usr/lib64/cifs-utils/cifs_idmap_sss.so
ld                  	auto  	/usr/bin/ld.bfd
nmap                	auto  	/usr/bin/ncat
python3             	auto  	/usr/bin/python3.6

To remove alternatives;

alternatives --remove-all python

And that is how easy it is to install Python.

Other Tutorials

Install ELK Stack on Rocky Linux 8

Install MongoDB on Rocky Linux 8

Install Latest Nodejs on Rocky Linux 8

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
gen_too
Co-founder of Kifarunix.com, Linux Tips and Tutorials. Linux/Unix admin and author at Kifarunix.com.

Leave a Comment