sw_vers

print macOS system version information

sw_vers --productName | --productVersion | --productVersionExtra| --buildVersion

Outputs macOS version information for the currently running operating system on the local machine.

With no options putputs a short list of version properties:

         % sw_vers
           ProductName:              macOS
           ProductVersion:           13.0
           ProductVersionExtra:      (a)
           BuildVersion:             22A100
The ProductName property provides the name of the operating system release (typically "macOS").
The ProductVersion property defines the version of the operating system release (for example, "11.3" or "12.0").
The ProductVersionExtra property defines the Rapid Security Response version, if one is installed on the operating system (for example, "(a)" or "(b)").
The BuildVersion property provides the specific revision of the operating system as generated by the macOS build system.

Options

One of the case-insensitive.options restricts the output to only that properity.
--productName
--productVersion
--productVersionExtra
--buildVersion

Examples

     % sw_vers --productName
     macOS

     % sw_vers --productVersion
     13.0

     % sw_vers --productVersionExtra
     (a)

     % sw_vers --buildVersion
     22A100

Compatibility

Previous versions respected $SYSTEM_VERSION_COMPAT to provide compatibility fallback versions for scripts which did not support the macOS 11.0+

FILES

/System/Library/CoreServices/SystemVersion.plist From plist:
     BuildID                E11C21BE-8D1C-11EF-8CD4-7C85970E9FD2  
     ProductBuildVersion    24B82  
     ProductCopyright       1983-2024 Apple Inc.  
     ProductName            macOS  
     ProductUserVisibleVersion     15.1  
     ProductVersion         15.1  
     iOSSupportVersion      18.1  

? macOS 15.1 October 27, 2022