Knowing your Linux distribution and version is essential for system management, package installation, and troubleshooting. The lsb_release command provides a standardized way to identify Linux distribution details, making it especially useful for administrators managing multiple distributions.

This article covers:

  • What lsb_release is
  • How to install it
  • Usage examples
  • Common use cases

What is lsb_release?

The lsb_release command displays essential Linux distribution details, including:

  • Distributor ID: The name of the Linux distribution (e.g., Rocky, Ubuntu).
  • Description: A friendly description with name and version.
  • Release: The version number.
  • Codename: The release’s codename (e.g., “Blue Onyx” for Rocky Linux 9).

This standardized output is useful for users and scripts, especially when working in diverse Linux environments.


How to Install lsb_release

Some distributions don’t include lsb_release by default. Here’s how to install it on popular Linux distributions:

Rocky Linux 9, AlmaLinux 9, and Oracle Linux 9

sudo dnf install lsb_release

Debian/Ubuntu

sudo apt update && sudo apt install lsb-release

CentOS/RHEL (older versions)

sudo yum install redhat-lsb-core

Using lsb_release: Command Options and Examples

The lsb_release command includes several options for displaying specific details. Here’s how to use them:

1. Display All Information

Use the -a option to view all distribution information:

lsb_release -a

Output Example:

Distributor ID:    Rocky
Description:       Rocky Linux release 9.0 (Blue Onyx)
Release:           9.0
Codename:          Blue Onyx

2. Display Only the Description

Use -d for a brief description of the distribution:

lsb_release -d

Output Example:

Description:    Rocky Linux release 9.0 (Blue Onyx)

3. Show Release Version

Use -r to display the release version only:

lsb_release -r

Output Example:

Release:    9.0

4. Display the Codename

Use -c to view the release codename:

lsb_release -c

Output Example:

Codename:    Blue Onyx

5. Show the Distributor ID

Use -i to view the distributor ID:

lsb_release -i

Output Example:

Distributor ID:    Rocky

Practical Use Cases for lsb_release

1. Automation and Scripting

lsb_release ensures compatibility in scripts across distributions. For example:

#!/bin/bash
OS_VERSION=$(lsb_release -r | awk '{print $2}')
if [[ "$OS_VERSION" == "9.0" ]]; then
    echo "Compatible OS version detected."
else
    echo "Incompatible OS version. Aborting."
fi

2. System Documentation and Reporting

Save system details to a file for easy reference:

echo "Server OS Information:" > system_info.txt
lsb_release -a >> system_info.txt

3. Conditional Package Management

Use lsb_release to apply conditional logic for package installations:

if [[ "$(lsb_release -i | awk '{print $3}')" == "Ubuntu" ]]; then
    sudo apt install example-package
elif [[ "$(lsb_release -i | awk '{print $3}')" == "Rocky" ]]; then
    sudo dnf install example-package
fi

4. Version-Specific Configurations

Adjust configurations based on OS codename:

if [[ "$(lsb_release -c | awk '{print $2}')" == "Blue Onyx" ]]; then
    echo "Applying settings for Rocky Linux 9 (Blue Onyx)"
    # Rocky Linux-specific settings here
fi

5. Troubleshooting and Technical Support

Share the output of lsb_release -a with support teams for accurate version-specific assistance.


Conclusion

The lsb_release command provides a convenient way to retrieve Linux distribution information, essential for scripting, troubleshooting, and documentation. Whether managing multiple distributions or ensuring compatibility in scripts, lsb_release is a valuable tool in any Linux administrator’s toolkit.

Use this guide to make the most of lsb_release and improve your Linux system management!