After detecting a GNU/Linux system through running uname, in a GNU/Linux distribution lsb_release -a is a good entry level utility you could use to [try to] find out the GNU/Linux distribution name and particular version1.

After detecting a Darwin (possibly macOS) system through running uname, there must be a Different (maybe not that much...) way to Ask the OS version number1. Even if it only works on macOS, it'd be useful.

This is similar to the /etc/release for other Unix / Linux, but I’d like to specifically target macOS to script a check of the version. In what way(s) is this possible?

  • 1
    lsb are specifically Linux tools as per apple.stackexchange.com/a/368245/237 As macOS is not Linux what are you looking for?
    – mmmmmm
    Sep 4, 2019 at 20:49
  • 1
    And you need to explain what you need as uname -a being arid is not helpful. Hint theis is macOS and many of us do not know what lsb etc provide.
    – mmmmmm
    Sep 4, 2019 at 20:58
  • 1
    What does lsb_release -a do (on a Linux system), and what exactly do you want to do with the result on macOS? Some more details on this might help to find suitable alternatives .
    – nohillside
    Sep 5, 2019 at 6:23

4 Answers 4


Here are some other options that you could use.

sysctl kern.version
kern.version: Darwin Kernel Version 16.7.0: Sun Jun  2 20:26:31 PDT 2019; root:xnu-3789.73.50~1/RELEASE_X86_64

sysctl kern.ostype
kern.ostype: Darwin

sysctl kern.osrelease
kern.osrelease: 16.7.0

sysctl kern.osrevision
kern.osrevision: 199506

And as an alternative to sw_vers

/usr/libexec/PlistBuddy -c "Print:ProductName" \
                        -c "Print:ProductVersion" \
                        -c "Print:ProductBuildVersion" /System/Library/CoreServices/SystemVersion.plist
Mac OS X

I don't know if all of this is imposed by Darwin, the manual page seems like it maybe is a Mac OS X (sic in my manual page as of Sep 2019) thing, but there is the awesome sw_vers:

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.6
BuildVersion:   yadda yadda yadda
$ _

LSB stands for "Linux Standard Base".

macOS isn't Linux, so it isn't part of the LSB project, and doesn't support LSB tools.

  • Actually, one of the major reasons for the LSB Specifications is that they provide a precise description of the APIs and ABIs required to run "Linux" applications independent of Linux. IOW, you should not need Linux to run an LSB-conformant Linux application, and you should not need to look at Linux to develop an LSB-conformant OS. For example, HP-UX, IBM AIX, and FreeBSD provide LSB-conformant ABIs and APIs that allow you to run LSB-conformant "Linux" applications unmodified. So, the argument that macOS doesn't support LSB because it isn't Linux is invalid, since that's actually one of … Sep 5, 2019 at 5:25
  • … the purposes of the LSB: to allow Operating Systems that are not Linux to be compliant with the LSB without having to derive from or look at Linux source code. Sep 5, 2019 at 5:26
  • 1
    @JörgWMittag But macOS makes no attempt to be compatible with Linux!
    – user101978
    Sep 5, 2019 at 5:41
  • @JörgWMittag But that assumes that the OS authors want to be compliant and can be bothered to write what they see as unnecessary code.
    – mmmmmm
    Sep 10, 2019 at 16:07

Use the standard way - uname - defined in POSIX so works in all Unix systems and sopme others that provide compatibility.

Examples from my Mac mini running macOS 10.14.6

uname -a gives all it can

Darwin mini12 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64

Given the question you link to the full answer is possibly alter the script in https://stackoverflow.com/a/56968182/151019 The code for macOS is the same as for Solaris except change the DIST and OS values

uname -v prints the operating system version. (actual POSIX definition is Write the current version level of this release of the operating system implementation.) For macOS it prints the Darwin version. The Linux man page says it prints the kernal version. (Solaris has the same definition as the macOS man page so I assume it is the version of the Solaris kernal.)

Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64

and uname -r just gives the number (POSIX definition - Write the current release level of the operating system implementation.)


Not the answer you're looking for? Browse other questions tagged .