# How to know the platform?

**URL:** <https://rubytalk.org/t/how-to-know-the-platform/42608>\
**Category:** ruby-talk\
**Created:** [29 November 2007 15:40 UTC](https://rubytalk.org/t/how-to-know-the-platform/42608 "2007-11-29T15:40:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Unbewusst\_Sein2](https://avatars.discourse-cdn.com/v4/letter/u/91b2a8/32.png) [@Unbewusst\_Sein2](https://rubytalk.org/u/Unbewusst_Sein2)\
**Post date:** [29 November 2007 15:40 UTC](https://rubytalk.org/t/how-to-know-the-platform/42608/1 "2007-11-29T15:40:01Z")

</div>

because i have some part of a script only running on MacOS X ony i'd  
like to know how to detect the platform from a ruby script.

as in java we have :  
public static String OS\_NAME = System.getProperty("[os.name](http://os.name)");  
public static String OS\_VERSION = System.getProperty("os.version");

ENV hash doen't contains any info like that.

I've found : RUBY\_PLATFORM giving :  
RUBY\_PLATFORM = powerpc-darwin8.9.0

> **···**
>
> --  
> Une Bévue

---

<div class="post-metadata">

**Author:** ![Kyle\_Schmitt](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@Kyle\_Schmitt](https://rubytalk.org/u/Kyle_Schmitt)\
**Post date:** [29 November 2007 17:07 UTC](https://rubytalk.org/t/how-to-know-the-platform/42608/2 "2007-11-29T17:07:03Z")

</div>

You can get the sysutils package ([http://sysutils.rubyforge.org/](http://sysutils.rubyforge.org/)) for  
some quick and easy access to that sort of thing. The downside is  
almost all of them are very gems dependent, so its difficult to  
install them standalone.

Sys/Admin (User & Group information, as well as some other stuff I  
don't use as much)  
Sys/Uname (Has some or all of the stuff you want, and is quite usefull)  
Sys/Host (just hostname stuff)  
Sys/Cpu

--Kyle  
#Example follows. Enjoy!

require 'rubygems'  
require 'sys/uname'  
require 'sys/host'  
Sys::Uname.release  
=\> "2.6.18-8.1.15.el5"  
Sys::Uname.uname  
=\> #\<struct Struct::UnameStruct sysname="Linux",  
nodename="[lxwrk1.trisalesco.com](http://lxwrk1.trisalesco.com)", machine="i686", version="#1 SMP Mon  
Oct 22 08:32:04 EDT 2007", release="2.6.18-8.1.15.el5"\>  
Sys::Uname.sysname  
=\> "Linux"  
Sys::Uname.version  
=\> "#1 SMP Mon Oct 22 08:32:04 EDT 2007"  
Sys::Uname.nodename  
=\> "[lxwrk1.trisalesco.com](http://lxwrk1.trisalesco.com)"  
Sys::CPU.processors  
=\> [#\<struct Struct::CPUStruct flags="fpu vme de pse tsc msr pae mce  
cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse  
sse2 ss ht tm pbe up cid xtpr", fpu=true, fdiv\_bug=false,  
vendor\_id="GenuineIntel", cpuid\_level="2", cache\_size="512 KB",  
bogomips="4800.05", wp=true, coma\_bug=false, f00f\_bug=false,  
fpu\_exception=true, model\_name="Intel(R) Pentium(R) 4 CPU 2.40GHz",  
processor="0", cpu\_mhz="2399.026", stepping="7", hlt\_bug=false,  
model="2", cpu\_family="15"\>]

---

<div class="post-metadata">

**Author:** ![Gavin\_Kistner3](https://avatars.discourse-cdn.com/v4/letter/g/dfb087/32.png) [@Gavin\_Kistner3](https://rubytalk.org/u/Gavin_Kistner3)\
**Post date:** [29 November 2007 19:10 UTC](https://rubytalk.org/t/how-to-know-the-platform/42608/3 "2007-11-29T19:10:04Z")

</div>

Please search the archives - this has come up at least twice recently,  
with discussion about regexps that do and don't work, and gems that  
exist to do this for you.

> **···**
>
> On Nov 29, 8:39 am, unbewusst.s...@weltanschauung.com.invalid (Une Bévue) wrote:
> 
> > because i have some part of a script only running on MacOS X ony i'd  
> > like to know how to detect the platform from a ruby script.

---

<div class="post-metadata">

**Author:** ![Richard1](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Richard1](https://rubytalk.org/u/Richard1)\
**Post date:** [29 November 2007 19:29 UTC](https://rubytalk.org/t/how-to-know-the-platform/42608/4 "2007-11-29T19:29:59Z")

</div>

You can detect the user's platform by utilizing the RUBY\_PLATFORM special variable.

Phrogz wrote:

> **···**
>
> > On Nov 29, 8:39 am, unbewusst.s...@weltanschauung.com.invalid (Une \> Bévue) wrote:  
> > &nbsp;&nbsp;
> > 
> > > because i have some part of a script only running on MacOS X ony i'd  
> > > like to know how to detect the platform from a ruby script.  
> > > &nbsp;&nbsp;&nbsp;&nbsp;  
> > > Please search the archives - this has come up at least twice recently,  
> > > with discussion about regexps that do and don't work, and gems that  
> > > exist to do this for you.

---

<div class="post-metadata">

**Author:** ![Unbewusst\_Sein2](https://avatars.discourse-cdn.com/v4/letter/u/91b2a8/32.png) [@Unbewusst\_Sein2](https://rubytalk.org/u/Unbewusst_Sein2)\
**Post date:** [29 November 2007 22:20 UTC](https://rubytalk.org/t/how-to-know-the-platform/42608/5 "2007-11-29T22:20:57Z")

</div>

> You can get the sysutils package ([http://sysutils.rubyforge.org/\](http://sysutils.rubyforge.org/%5C)) for  
> some quick and easy access to that sort of thing. The downside is  
> almost all of them are very gems dependent, so its difficult to  
> install them standalone.

hum, I'll see what's inside sys-uname-0.8.2...

i've found "tc\_uname.rb" giving some light on what to check in  
RUBY\_PLATFORM

i think there is no need, for me, to install sys-uname.

thanks for your reply !

> Sys/Uname (Has some or all of the stuff you want, and is quite usefull)

[...]

> Sys::Uname.sysname  
> =\> "Linux"  
> Sys::Uname.version  
> =\> "#1 SMP Mon Oct 22 08:32:04 EDT 2007"

Ok, it's just what i want.

> **···**
>
> Kyle Schmitt \<kyleaschmitt@gmail.com\> wrote:
> 
> --  
> Une Bévue

---

<div class="post-metadata">

**Author:** ![Unbewusst\_Sein2](https://avatars.discourse-cdn.com/v4/letter/u/91b2a8/32.png) [@Unbewusst\_Sein2](https://rubytalk.org/u/Unbewusst_Sein2)\
**Post date:** [29 November 2007 22:20 UTC](https://rubytalk.org/t/how-to-know-the-platform/42608/6 "2007-11-29T22:20:57Z")

</div>

yes, thanks it's exactly what i did :  
&nbsp;&nbsp;def isOSX?  
&nbsp;&nbsp;&nbsp;&nbsp;(/.\*darwin.\*/ === RUBY\_PLATFORM)  
&nbsp;&nbsp;end

the version too;

&nbsp;&nbsp;def version  
&nbsp;&nbsp;&nbsp;&nbsp;RUBY\_PLATFORM.gsub(/^[^\d]\*([\d|\.]\*)/, '\1')  
&nbsp;&nbsp;end

It's ok for MacOS X, but i'd like also the get the various nix\*

> **···**
>
> Richard \<richafoxx@comcast.net\> wrote:
> 
> > You can detect the user's platform by utilizing the RUBY\_PLATFORM  
> > special variable.
> 
> --  
> Une Bévue
