The Importance of Knowing Your OS Version
If you are trying to install a complex, professional software package like Adobe Premiere Pro, Docker, or Homebrew, the installer will often perform a strict background check to ensure your Mac is running a compatible operating system. If the software requires macOS 13.4, and you are running macOS 13.2, the installation will abruptly fail.
While an average user can simply click the Apple Logo in the top left corner of the screen and select “About This Mac” to see a friendly graphical display of their OS version (like “macOS Sonoma”), that interface is completely useless if you are writing an automated bash script that needs to mathematically verify the OS version before executing.
To pull the exact, numerical version data of your macOS installation directly into the terminal, you must use the sw_vers (Software Version) command.
Step 1: Open the Terminal
Because you are simply querying basic system information, you do not need administrative privileges. You can run this command as a standard user.
- Press Command + Space to open Spotlight Search.
- Type
Terminaland press Enter.
Step 2: The Basic Version Check
To see the complete version block for your Mac, simply type the command and press Enter:
sw_vers
The terminal will output three very specific lines of data:
- ProductName: The official marketing name of the OS (e.g.,
macOS). - ProductVersion: The exact numerical version of the OS (e.g.,
14.4.1). - BuildVersion: The highly specific, internal Apple build number for that exact update (e.g.,
23E224).
The BuildVersion is particularly important for enterprise IT administrators. Apple occasionally releases silent security patches that do not actually change the primary ProductVersion number, but they do increment the BuildVersion. Checking the build number is the only way to prove a machine is fully patched against a zero-day exploit.
Step 3: Extracting Specific Values for Scripts
If you are writing a custom bash script that needs to check if the user is running macOS 14 before allowing them to install a program, parsing the three-line output of the basic sw_vers command using grep or awk is tedious and prone to formatting errors.
Apple built dedicated flags into the command to isolate exactly one piece of data, completely stripping away the labels so your script can read the raw number instantly.
To isolate just the numerical product version, use the -productVersion flag:
sw_vers -productVersion
The terminal will output absolutely nothing except the number itself (e.g., 14.4.1). This allows you to instantly assign that value to a variable in your shell script (OS_VER=$(sw_vers -productVersion)).
Similarly, to isolate just the internal Apple build number, use the -buildVersion flag:
sw_vers -buildVersion
Alternative: Combining with uname
While sw_vers is perfect for determining the exact version of the macOS operating system itself, it does not tell you if the Mac is running on an older Intel chip or a modern Apple Silicon (M1/M2/M3) processor.
If your script needs to verify the OS version and the processor architecture before downloading a binary, you should combine sw_vers with the standard UNIX uname -m command, which will output either x86_64 (Intel) or arm64 (Apple Silicon).