We're an ISO27001:2013 Certified Supplier

distro list

Most major Linux installations include some facility for working out which version of which distribution they are. Often this is a file in the /etc directory; for example, on a Red Hat Enterprise Linux (RHEL) system it’s /etc/redhat-release:

$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.10 (Santiago)

CentOS, being based on RHEL, uses the same file. The contents of the equivalent file on a Debian system, /etc/debian_version, are much more terse:

$ cat /etc/debian_version
9.5

That’s factual, but it doesn’t elaborate on what that means. Whereas RHEL includes the codename of the release, “Santiago”, Debian assumes you know that 9.5 is known internally as “Stretch”.

Ubuntu can be even more confusing. Like CentOS, it’s a distribution derived from a parent, in this case Debian:

$ cat /etc/debian_version
buster/sid

Here, the version of Ubuntu in use was released while the parent Debian distribution on which it is based was “still in development” (“sid”). The file doesn’t tell us what the actual Ubuntu release was called at all.

A standard interface

Fortunately, it’s standards-to-the-rescue. The Linxu Standard Base (“LSB”) standard defines the program lsb_release which should give consistent and useful information. Here is its output on a Ubuntu system, and you’ll probably agree it’s much more helpful than /etc/debian_version:

$ lsb_release -cdi
Distributor ID: Ubuntu
Description: Ubuntu 18.04 LTS
Codename: bionic

The options used:

-c – Display the code name of the currently installed distribution.
-d – Display a description of the currently installed distribution.
-i – Display the distributor’s ID.

Putting it to work

This lends itself very well to scripting. Consider the challenge of installing the Apache web server on a collection of servers, some Red Hat and some Debian. The package name differs, as does the package manager used to install it, but that’s easily accommodated:

#!/bin/bash

# Use yum to install httpd on RHEL systems, and
# apt to install apache2 on Debian systems.
DIST=$(lsb_release -is)
if [ “${DIST}” = “Debian” ]; then
    apt install -y apache2
elif [ “${DIST}” = “RedHatEnterpriseServer” ]; then
    yum install -y httpd
else
    echo “Unrecognised distribution ${DIST}”
fi

What’s your favourite Linux Tip?

Drop us mail, and maybe we’ll feature your tip in future.

Leave a Reply

Your email address will not be published. Required fields are marked *

Secure. Reliable. Scalable.

If that doesn't describe your current Linux systems, check out our FREE Linux Survival Guide to help you get your systems up to scratch today!

  • This field is for validation purposes and should be left unchanged.