How To

 

RHEL 8 setup

This Hello, World shows how to install and run a package on Red Hat Enterprise Linux 8. If you haven’t already, download and install RHEL 8, and register it with Red Hat Subscription Management.  If you don’t already have a subscription, a no-cost developer subscription will be created for you when you download through developers.redhat.com.

Make sure you have the core Red Hat Enterprise Linux 8 development tools (make, git, gcc) installed. If you didn’t select Development Tools during installation, install them now:

$ sudo yum groupinstall ‘Development Tools’

Note: if sudo isn’t enabled for your user ID, see How to enable sudo on Red Hat Enterprise Linux. During system installation, checking the box Make this user administrator enables sudo for your user ID.

 

Install Python

First, see what Python modules are available as part of the Application Stream Repository:

 

$ sudo yum module list | grep -i python
python27       2.7 [d] default [d]                    Python programming language, version 2.7
python36       3.6 [d][e] build, default [d]          Python programming language, version 3.6

For the `python36` module, there are two profiles: `default` and `build`.  For development, use the `build` profile. This causes the `python36-devel` package to be installed that are needed to build any Python module that use dynamically loaded code such as C/C++.

Install Python 3.6:

$ sudo yum module install python36/build

Python is now installed. For an explanation of the above command, see Working with AppStreams below.

Check the Python version and the path:

$ python3 -V
Python 3.6.7
$ which python3
/usr/bin/python3

You can also use `python3.6` as the command to specifically run Python 3.6.  

The Python modules `pip` and `venv` for installing modules and working with Python virtual environments are installed. There are wrapper scripts in `/usr/bin` to run these, but running them as modules without using the wrapper script is strongly recommended.  This helps avoid conflicts and other surprises if you have multiple versions of Python installed.

$ python3 -m pip …
$ python3 -m venv ...

More info about what is installed on your system is available with the following commands:

$ ls /usr/bin/py* /usr/bin/pip3*  # see what’s in /usr/bin
$ rpm -qil python36    # get the info and list of files in the python36 meta package
$ python3 -m pip list    # installed modules
$ yum list installed python\*    # list installed packages matching python*

Note: by default there is no `/usr/bin/python` without a version number.  It is strongly suggested to use a specific version such as `python3` or better, `python3.6`. This avoids surprises and is a best practice.

While you can install a package which will make `/usr/bin/python` give your choice of Python 3 or Python 2, it isn’t recommended. At some point the expectation about what version of Python you get without specifying a version will be wrong.

See [Python on RHEL 8](link tbd) for more information.
 

Hello, World

Let’s create a simple Python program that can be run from the command line. Using a text editor such as vi, nano, or gedit, create a file named `hello.py` with the following content:

hello.py

#!/usr/bin/python3.6 import sys version = "Python %d.%d" % (sys.version_info.major, sys.version_info.minor) print("Hello, Red Hat Developer World from",version)

Save it and exit the editor. Then, make the program executable, and run it:

$ chmod +x hello.py
$ ./hello.py
Hello, Red Hat Developer World from Python 3.6

 

Working with Appstreams

The first step is to see what modules are available the Applications Streams (appstream) repo:

$ sudo yum module list  # list all available modules in appstream

Or, find just the modules named `nodejs`

$ sudo yum module list nodejs

From the output you can see that Node.js 10 is the default module to install, note the `[d]`.  You could have simply typed the following to install the default nodejs module.

$ sudo yum module install nodejs

Or even, shorter using ‘@’:

$ sudo yum install @nodejs

The above commands would have installed the nodejs with the default profile. A profile is group, usually a subset, of the packages in a module.  For this module the default profile is named `default. In the steps above, the `development` profile was chosen to get the packages in the development profile installed.

To find out more about a module, use one of the following commands:

$ yum module info nodejs  # get info about the default nodejs module
$ yum module info nodejs:10   # get info about a specific module stream
Last updated: November 15, 2018