Linux Tutorials

RHEL Eight set up Python Three or Python 2 utilizing yum

I want to put in Python Three for Ansible IT automation instrument on RHEL Eight. How do I set up Python Three on RHEL Eight? Is it attainable to put in Python 2 for legacy apps on RHEL Eight?

Crimson Hat Enterprise Linux (RHEL Eight) doesn’t set up Python Three or 2 by default as Crimson Hat didn’t need to set a default. Nonetheless, system directors can set up Python Three or 2 as per wants utilizing numerous strategies. This web page exhibits how you can set up Python Three or Python 2.7 on RHEL Eight utilizing yum command.

Adblock detected 😱

My web site is made attainable by displaying on-line commercials to my guests. I get it! Advertisements are annoying however they assist hold this web site working. It’s exhausting to maintain the location working and producing new content material when so many individuals block advertisements. Please contemplate donating cash to the nixCraft by way of PayPal/Bitcoin, or change into a supporter utilizing Patreon.

The way to Set up Python Three / Python 2.7 on RHEL Eight

The process for putting in Python Three on RHEL Eight is as follows:

Open the Terminal utility or window.Seek for python package deal in RHEL Eight, run: sudo yum search python3To put in python Three on RHEL Eight, run: sudo yum set up python3To put in python 2 on RHEL Eight, run: sudo yum set up python2Improve python Three in RHEL Eight, run: sudo yum improve python3Improve python 2 in RHEL Eight, run: sudo yum improve python2

Allow us to see all instructions and instance in particulars.

The way to discover out Python package deal names on RHEL Eight

Attempt any one of many following syntax together with grep command:
sudo yum search python3 | extra
sudo yum search python2 | extra
sudo yum search python36
sudo yum search python2 | grep ‘python2.x86_64’
You possibly can present detailed data earlier than putting in package deal as properly:
sudo yum information python2.x86_6
sudo yum information python36
Finding info about Python in RHEL 8 using yum command

RHEL Eight set up Python Three

Sort the next yum command to put in Python Three on Crimson Hat Enterprise Linux model Eight:
sudo yum set up python3
OR
sudo yum module set up python36
RHEL 8 install Python 3 using yum command
Confirm set up by typing the kind command/command command:
$ kind -a python3
python3 is /usr/bin/python3
$ command -V python3
python3 is hashed (/usr/bin/python3)
$ python3 –version
Python Three.6.6

A pattern script in Python Three

Create a file named take a look at.py:

#!/usr/bin/python3
import os, time
print(“This can be a take a look at code for Python3”)
print(“Hi there %s, allow us to be buddies!” % os.environ[“USER”])
print(“Right this moment is %s” % time.strftime(“%c”))

#!/usr/bin/python3
import os, time
print(“This can be a take a look at code for Python3”)
print(“Hi there %s, allow us to be buddies!” % os.environ[“USER”])
print(“Right this moment is %s” % time.strftime(“%c”))

Run it as follows:
$ chmod +x take a look at.py
$ ./take a look at.py
Running python3 app on RHEL 8

A observe for Ansible customers

Arrange your hosts file as follows in your management node to make use of Ansible as automation instrument for RHEL Eight server:

[all:vars]
ansible_user=vivek
ansible_port=22
ansible_python_interpreter=‘/usr/bin/env python3’

[all:vars]
ansible_user=vivek
ansible_port=22
ansible_python_interpreter=’/usr/bin/env python3′

Now run it as normal:
ansible-playbook -i hosts duties/7-secure-rhel8-vm.yml

RHEL Eight set up Python 2

Allow us to see how you can set up Python 2.7 on RHEL Eight:
sudo yum set up python27
OR
sudo yum module set up python27
RHEL 8 install Python 2 using yum command
Allow us to discover out details about put in model of Python 2.7 in RHEL Eight:
$ kind -a python2
$ command -V python2
$ python2 –version
How to install Python 3 on Red Hat Enterprise Linux and verify it

Can I set up each Python Three.6 and Python 2.7 on RHEL Eight?

Sure. It’s attainable to put in each variations concurrently:
sudo yum module set up python36 python27
Pattern outputs:

Updating Subscription Administration repositories.
Updating Subscription Administration repositories.
Final metadata expiration examine: zero:09:22 in the past on Tuesday 05 March 2019 02:09:48 PM EST.
Dependencies resolved.
========================================================================================
Bundle Arch Model Repository Measurement
========================================================================================
Putting in group/module packages:
python36
x86_64 Three.6.6-17.el8+2102+a4bbd900 rhel-Eight-for-x86_64-appstream-beta-rpms 22 okay
python2 x86_64 2.7.15-15.el8+2103+c6cdb4cb rhel-Eight-for-x86_64-appstream-beta-rpms 106 okay
python2-pip
noarch 9.zero.Three-10.el8+2056+8b2f0fde rhel-Eight-for-x86_64-appstream-beta-rpms 2.zero M
python2-setuptools
noarch 39.zero.1-10.el8+1958+74bcdd68 rhel-Eight-for-x86_64-appstream-beta-rpms 643 okay
python2-libs
x86_64 2.7.15-15.el8+2103+c6cdb4cb rhel-Eight-for-x86_64-appstream-beta-rpms 6.zero M
Putting in module profiles:
python27/default
 
python36/default
 
 
Transaction Abstract
========================================================================================
Set up 5 Packages
 
Complete obtain dimension: Eight.7 M
Put in dimension: 36 M
Is that this okay [y/N]:

Updating Subscription Administration repositories.
Updating Subscription Administration repositories.
Final metadata expiration examine: zero:09:22 in the past on Tuesday 05 March 2019 02:09:48 PM EST.
Dependencies resolved.
========================================================================================
Bundle Arch Model Repository Measurement
========================================================================================
Putting in group/module packages:
python36
x86_64 Three.6.6-17.el8+2102+a4bbd900 rhel-Eight-for-x86_64-appstream-beta-rpms 22 okay
python2 x86_64 2.7.15-15.el8+2103+c6cdb4cb rhel-Eight-for-x86_64-appstream-beta-rpms 106 okay
python2-pip
noarch 9.zero.Three-10.el8+2056+8b2f0fde rhel-Eight-for-x86_64-appstream-beta-rpms 2.zero M
python2-setuptools
noarch 39.zero.1-10.el8+1958+74bcdd68 rhel-Eight-for-x86_64-appstream-beta-rpms 643 okay
python2-libs
x86_64 2.7.15-15.el8+2103+c6cdb4cb rhel-Eight-for-x86_64-appstream-beta-rpms 6.zero M
Putting in module profiles:
python27/default
python36/default Transaction Abstract
========================================================================================
Set up 5 Packages Complete obtain dimension: Eight.7 M
Put in dimension: 36 M
Is that this okay [y/N]:

How do I set default model of Python on RHEL Eight?

One can set Python Three as default by working the straightforward command:
sudo alternate options –set python /usr/bin/python3
python –version
Pattern outputs:

Python Three.6.6

Equally one can set Python 2 as default model for RHEL Eight based mostly desktop or server atmosphere from the bash shell:
sudo alternate options –set python /usr/bin/python2
python –version

How do I take away python default on RHEL Eight?

The syntax is straightforward:
sudo alternate options –remove python /usr/bin/python2
OR
sudo alternate options –remove python /usr/bin/python3

Conclusion

This web page confirmed how you can set up Python Three.6 or Python 2.7 on RHEL Eight utilizing the yum command. For extra data please see this web page right here and right here.

Posted by: Vivek Gite

The creator is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a coach for the Linux working system/Unix shell scripting. Get the newest tutorials on SysAdmin, Linux/Unix and open supply matters by way of RSS/XML feed or weekly electronic mail e-newsletter.

Source link

Related Articles

Back to top button