Linux – On what Linux distributions can I rely on the presence of /etc/os-release

distributionslinux

I'm trying to find a way to determine Linux distribution name and version that would work on most (or ideally, all) modern distributions. I noticed that /etc/os-release contains the info I need on the distributions I tried (CentOS, Debian), but how safe is it to rely on the presence of it? Commands such as uname -a don't really contain the same info, and lsb_release is apparently not present on e.g. minimal CentOS.

Is there a quick way to find out exactly what distros come with /etc/os-release? Moreover, is /etc/os-release guaranteed to contain NAME, VERSION and PRETTY_NAME fields?

Best Answer

Any system running systemd should have /etc/os-release, which is specified as part of systemd. Some systems without systemd might have it too (e.g. Debian 8 where systemd is optional but /etc/os-release is installed in all cases).

According to the specification, all fields are optional, and some have defaults ("Linux" for NAME and PRETTY_NAME).

You’ll find more background in the /etc/os-release announcement.

Related Question