Question

In node you have access to process.os() and process.platform, which give you one of 5 values:

'darwin'
'freebsd'
'linux'
'sunos'
'win32'

But how do you print out the specific distro, such as one of these?

http://en.wikipedia.org/wiki/List_of_Linux_distributions

'ubuntu'
'gentoo'
'fedora'
'SUSE Linux'
'CentOS'
dozens/hundreds more

If there is no standard approach, is there any current preferred solution out there? Mainly this would be useful for being able to tell the difference (programmatically) between ubuntu and some of the other popular EC2 image oses.

Was it helpful?

Solution 2

To summarize all the responses: There is no easy way to determine the current Linux distribution.

However here are a few thing you could start with.

  • uname -v usually gives you a long string with some informations. (E.g.: #66-Ubuntu SMP Thu Apr 25 03:27:11 UTC 2013)
  • Debian /etc/debian_version, but this is set in Ubuntu, too!
  • Ubuntu: /etc/lsb-release and /etc/os-release
  • SuSe: /etc/SuSE-release
  • Many distros also write to /etc/issue

If you have a list of possible distributions that could happen, you should be able to get that information somehow. If you want a generic approach I'll guess there will be no absolute answer.

OTHER TIPS

The linux_distribution() function in Python's platform module should work with most of the more common and many of the less common Linux distributions:

python -c "import platform; print platform.linux_distribution()"

Executing a shell command from node.js was answered here: node.js shell command execution

On node.js,

const os = require('os');
console.log(os.version());

should do the trick. On my machine it prints #29~20.04.1-Ubuntu SMP Wed Aug 11 15:58:17 UTC 2021 on console

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top