Last updated:
💻 Geeky Vibes! Check out our partner WrinkledT: Sustainable Style With a POP 💥 🌈 for the Soul (and the Planet!) 🌎💚

When automating build processes or install scripts, it may be necessary to adjust steps taken based on the operating system version. Knowing which macOS version you are running is important and finding such information via the command line is critical when automating build process that can be used by various engineers with different versions of macOS. Below we will cover two methods to find quickly which macOS version you are currently running.

💡 Did you know? Apple’s operating systems started as the “Classic” Mac OS in 1984, followed by just “Mac OS” in 1996. The current operating system is macOS but was originally branded “Mac OS X” until 2012, then “OS X” until 2016.

👉 If you’d rather to use a point-and-click solution, instead of command line, to find out which version of macOS you are running, then check out the guide from apple’s website which also include the detail of latest versions available. See https://support.apple.com/en-us/HT201260.

Using system_profiler

The system_profiler command line utility provide system hardware and software configuration. The details that you can get from this utility goes way beyond the macOS version and can be slow to run. If you are only interested in the macOS version, make sure to use the command line argument SPSoftwareDataType. See example below.

[me@me-macOS: ~]$ system_profiler SPSoftwareDataType
Software:

    System Software Overview:

      System Version: macOS 10.14.6 (18G103)
      Kernel Version: Darwin 18.7.0
      Boot Volume: Macintosh HD
      Boot Mode: Normal
      Computer Name: jdoe-macOS
      User Name: John Doe (jdoe)
      Secure Virtual Memory: Enabled
      System Integrity Protection: Enabled
      Time since boot: 70 days 14:18

The benefit of using system_profiler is that it will properly reflect the macOS branding.

If you are only interested in getting your macOS version then sw_vers is probably better suited as it is an utility specificaly made to print Mac OS X operating system version information.

[me@me-macOS: ~]$ sw_vers 
ProductName:	Mac OS X
ProductVersion:	10.14.6
BuildVersion:	18G103

If you only care about the version number then you can run sw_vers -productVersion this way you don’t need to parse the output, all you get is the version number. You can also use the argument -productName or -buildVersion, check man sw_vers for the details.

[me@me-macOS: ~]$ sw_vers -productVersion
10.14.6

If you only care about major and minor version, then you could simply use bash substitution.

[me@me-macOS: ~]$ vers=`sw_vers -productVersion`
[me@me-macOS: ~]$ echo ${vers%.*}
10.14

How to get the macOS Friendly Name?

While I will use the numerical version of macOS in automation scripts, it is sometime helpful to know what is the friendly name or code name of the corresponding version.

Unfortunately neither sw_vers or system_profiler the friendly codename of your macOS version. You may find it in some random output with system_profiler but it may vary from version to version and depending on the software installed. Any alternative you may find online with parsing the license agreement or calling a remote support page would be unreliable and inconsistent between versions.

To get the firendly name, and use it in your automation scripts reliably, you will have to use an associative array containing all the versions and names then do a lookup based on your current version number.

👉 Find some examples of Bash Associative Array with my Complete Guide on How To Use Bash Arrays.

Below is a summary table of the Major.Minor macOS versions and the corresponding Code Name.

VersionCode Name
12Monterey
11Big sur
10.15Catalina
10.14Mojave
10.13High Sierra
10.12Sierra
10.11El Capitan
10.10Yosemite
10.9Mavericks
10.8Mountain Lion
10.7Lion
10.6Snow Leopard
10.5Leopard
10.4Tiger
10.3Panther
10.2Jaguar
10.1Puma
10.0Cheetah
💻 Geeky Vibes! Check out our partner WrinkledT: Sustainable Style With a POP 💥 🌈 for the Soul (and the Planet!) 🌎💚
GET UNIQUE TIPS AND THE LATEST NEWS BY SUBSCRIBING TO MY NEWSLETTER.
AND FOLLOW ME ON