Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find name of linux distro from java

We are writing a small library in java that needs to collect information from the underlying system. We are able to read most of the stuff from system properties in java, but we cannot seem to find the right way to extract the name of the distro when run on linux. The call

System.getProperty("os.name");

return "Linux" (which we also collect) but we are looking for a way to get e.g. "Ubuntu" as well. We need this solution in java and would like to not have to do some /etc/release parsing

like image 264
soren.enemaerke Avatar asked Dec 02 '10 11:12

soren.enemaerke


People also ask

What kind of Linux do I have?

The command “uname -r” shows the version of the Linux kernel that you're currently using. You'll now see which Linux kernel you're using.


2 Answers

You can try invoking lsb_release -i, but this is not guaranteed to work.

like image 101
Ignacio Vazquez-Abrams Avatar answered Nov 15 '22 09:11

Ignacio Vazquez-Abrams


To do this reliably and accurately is impossible, the best I can suggest is to take the output of 'uname -a' and use that.

Note: This is not a Java limitation - there is simply no common (and accurate) means of identifying a distribution.

like image 39
Arafangion Avatar answered Nov 15 '22 07:11

Arafangion