# Detect Mac OS X Version

**URL:** <https://www.ruby-forum.com/t/detect-mac-os-x-version/125646>\
**Category:** Ruby\
**Created:** [January 10, 2008, 10:40pm UTC](https://www.ruby-forum.com/t/detect-mac-os-x-version/125646 "2008-01-10T22:40:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Filipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/35a633/32.png) [@Filipe](https://www.ruby-forum.com/u/Filipe)\
**Post date:** [January 10, 2008, 10:40pm UTC](https://www.ruby-forum.com/t/detect-mac-os-x-version/125646/1 "2008-01-10T22:40:47Z")

</div>

After Googling for a while I couldn’t find a way of detecting the Mac  
OS X version ruby is running on. I tryed the RUBY\_PLATFORM constant  
but it only tells me I’m running Mac OS, not its version.

Is there any other way of detecting wether the script is beeing run on  
10.4 or 10.5?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![Filipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/35a633/32.png) [@Filipe](https://www.ruby-forum.com/u/Filipe)\
**Post date:** [January 10, 2008, 10:51pm UTC](https://www.ruby-forum.com/t/detect-mac-os-x-version/125646/2 "2008-01-10T22:51:23Z")

</div>

On Jan 10, 2008 4:40 PM, Filipe [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> After Googling for a while I couldn’t find a way of detecting the Mac  
> OS X version ruby is running on. I tryed the RUBY\_PLATFORM constant  
> but it only tells me I’m running Mac OS, not its version.
> 
> Is there any other way of detecting wether the script is beeing run on  
> 10.4 or 10.5?

you can always run “sw\_vers -productVersion” as a system command…

---

<div class="post-metadata">

**Author:** ![Filipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/35a633/32.png) [@Filipe](https://www.ruby-forum.com/u/Filipe)\
**Post date:** [January 10, 2008, 10:54pm UTC](https://www.ruby-forum.com/t/detect-mac-os-x-version/125646/3 "2008-01-10T22:54:19Z")

</div>

On Jan 10, 2008, at 3:40 PM, Filipe wrote:

> After Googling for a while I couldn’t find a way of detecting the Mac  
> OS X version ruby is running on. I tryed the RUBY\_PLATFORM constant  
> but it only tells me I’m running Mac OS, not its version.
> 
> Is there any other way of detecting wether the script is beeing run on  
> 10.4 or 10.5?

The uname command returns the Darwin OS version, where Mac OS 10.4 is  
Darwin 8.x and Mac OS 10.5 is Darwin 9.x, so this should work:

os\_version = `uname -r`  
if os\_version =~ /^8/  
# Tiger  
elsif os\_version =~ /^9/  
# Leopard  
end

Hope this helps,

Lyle

---

<div class="post-metadata">

**Author:** ![Filipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/35a633/32.png) [@Filipe](https://www.ruby-forum.com/u/Filipe)\
**Post date:** [January 11, 2008, 12:33am UTC](https://www.ruby-forum.com/t/detect-mac-os-x-version/125646/4 "2008-01-11T00:33:52Z")

</div>

or look in the ENV for variables that you can parse.

Lyle J. wrote:

> On Jan 10, 2008, at 3:40 PM, Filipe wrote:
> 
> > After Googling for a while I couldn’t find a way of detecting the Mac  
> > OS X version ruby is running on. I tryed the RUBY\_PLATFORM constant  
> > but it only tells me I’m running Mac OS, not its version.
> > 
> > Is there any other way of detecting wether the script is beeing run on  
> > 10.4 or 10.5?
