1

I've been looking for some solution to find the name and version of the Linux distribution where I am running my Java code, eg. Ubuntu 18.04, CentOS 6, etc.

I am aware of files as /etc/os-release, or /etc/*release* (have read other answers), which are meant for such information, but am looking for currently available solutions so that I don't have to reinvent the wheel and don't have to bother about the list of files to check and their keys.

Also, I found one lib - github.com/will/oslib but it has just 18 stars and less forks.

From a product perspective, I'd love to avoid reinventing the wheel, and also avoid managing the list of files and the key name to check for to find linux distro information.

  • 1
    There is no standard way to query for what distro and release a Linux box is. There are things to look at that let you determine if it is a Debian or derivative (and the differences will tell you which one) and what release (but that is based on which derivative of Debian), and there are similar for Redhat and other major distributions - typically the presence or content of specific files. Depending on what you are trying to do, there may be other ways of making the determination.... – ivanivan Jul 4 at 1:26
0

You already found /etc/os-release. I would read it with the io library.

This is a simple text file like this:

NAME="Ubuntu"
VERSION="18.04.2 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.2 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

Since it is very simple, I guess that no one has created an open source library for this.

  • 1
    /etc/os-release is well-supported with distros having systemd. However, there are legacy ones as Cent OS 6 which have different file - /etc/centos-release, with a different key instead of PRETTY_NAME. Just wanted to have something which has this mapping already made. Thanks btw – Himanshu Shekhar Jul 4 at 13:11
  • @HimanshuShekhar thank you for this hint. I thought all current distributions have this file. – guettli Jul 4 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.