I frequently find myself SSHing into various OS X machines, and it'd be useful if I could tell what version of OS X I was on when I'm doing that. uname -a doesn't quite work, since Darwin kernel versions don't always change with the rest of the system.
Asked
Active
Viewed 4.0k times
69
Benjamin Pollack
- 985
- 1
- 7
- 11
5 Answers
79
sw_vers
My suggestion is to use sw_vers. Example output as of 10.6.4:
> sw_vers
ProductName: Mac OS X
ProductVersion: 10.6.4
BuildVersion: 10F569
The answer that suggested system_profiler | grep 'System Version' is what I have tried to use in the past, but it has 2 problems.
- It is slow since it generates a full system_profiler dump of the machine, gathering all hardware and software inventory information.
- The output of system_profiler has changed over time. e.g. output of
grepfor 'Serial Number' on 10.6.4 is "Serial Number (system): ZNNNNNZNZZZ", whereas on 10.4.11 it was "Serial Number: ZNNNNZNZZZZ" - importance being the parse-ability of the output and the add " (system)" piece can be problematic unless you are expecting the change.
Joshua Pinter
- 1,150
- 10
- 9
Mike Gray
- 1,561
- 12
- 13
-
1I'd flip this around. ``` Use sw_vers … --------------------------- The answer that suggested `system_profiler`… ``` – Tim Visher Nov 30 '15 at 15:09
-
@TimVisher Agreed. I just edited his answer to put it at the top. – Joshua Pinter Jan 06 '17 at 15:14
38
The easiest way is:
$ sw_vers -productVersion
10.6.4
From http://tinyapps.org/blog/mac/201008140700_os_x_version_terminal.html:
$ sw_vers ProductName: Mac OS X ProductVersion: 10.6.4 BuildVersion: 10F569 $ sw_vers -productVersion 10.6.4Especially handy when resetting a password in single user mode, since the method varies based on which version of OS X is running.
Benjamin Oakes
- 480
- 3
- 6
-
Thanks for the shout-out Benjamin! I've updated the post to include checking an offline OS X install like so: `grep -2 ProductVersion /System/Library/CoreServices/SystemVersion.plist`. Aloha, Miles – Miles Wolbe Sep 13 '16 at 20:44
8
Try this:
system_profiler | grep 'System Version'
Mike Gray's answer is better than this. Please see that
kbyrd
- 1,386
- 13
- 18
-
4
-
Single-user mode `system_profiler SPSoftwareDataType` wins where `sw_vers` loses. – Devon May 05 '18 at 17:33
6
Here is a Blog article with instructions How to Get the Mac OS X Version in a Shell Script
OS_VERSION=`/usr/bin/defaults read "$3/System/Library/CoreServices/SystemVersion" ProductVersion`
echo "$OS_VERSION"
Ken Williams
- 206
- 1
- 9
Larry Smithmier
- 465
- 2
- 10
- 14
-
1This is very useful for finding the version of a non-active operating system, eg. a volume that is being repaired or such. – ylluminate Aug 04 '15 at 22:29
3
The system_profiler can be run as system_profiler SPSoftwareDataType. No need to grep through huge output.
αғsнιη
- 40,939
- 15
- 71
- 114
user242114
- 101
- 1
- 1
- 4
-
This does not provide an answer to the question. Once you have sufficient [reputation](https://unix.stackexchange.com/help/whats-reputation) you will be able to [comment on any post](https://unix.stackexchange.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/228103) – Jeff Schaller Jan 28 '18 at 15:08
-
@JeffSchaller looks the answer is fine. It does an answer to the question. – αғsнιη Jan 28 '18 at 15:19
-
-
Perhaps it’s meant to be a comment of https://unix.stackexchange.com/a/584/117549? – Jeff Schaller Jan 28 '18 at 15:32
-
1Yes, it does return in "System Version" part, see [OS X Version from Command Line](https://scottlinux.com/2011/11/18/os-x-version-from-command-line/), it is an answer to me instead of a comment IMO. – αғsнιη Jan 28 '18 at 16:53