# Can a Ruby program determine whether it's running on a 32-bit or 64-bit system?

**URL:** <https://www.ruby-forum.com/t/can-a-ruby-program-determine-whether-its-running-on-a-32-bit-or-64-bit-system/147552>\
**Category:** Ruby\
**Created:** [September 3, 2008, 2:47am UTC](https://www.ruby-forum.com/t/can-a-ruby-program-determine-whether-its-running-on-a-32-bit-or-64-bit-system/147552 "2008-09-03T02:47:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![epasquier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/2bfe46/32.png) [@epasquier](https://www.ruby-forum.com/u/epasquier)\
**Post date:** [September 3, 2008, 2:47am UTC](https://www.ruby-forum.com/t/can-a-ruby-program-determine-whether-its-running-on-a-32-bit-or-64-bit-system/147552/1 "2008-09-03T02:47:43Z")

</div>

I can’t go by RUBY\_PLATFORM – I’m setting up a new 32-bit Linux box,  
and RUBY\_PLATFORM is set to “i686-linux”.

Or maybe this is a bug – repaved machine, installed Fedora Core 9,  
downloaded and built a vanilla Ruby 1.8.6 – but I see this on another  
32-bit Linux box as well (this one’s a virtual host, but `cat /proc/ cpuinfo`  
suggests it’s 32-bit)

If anyone’s wondering, this is related to the Komodo debugger. The  
ruby-debug-base component is not 32/64-bit universal, so I need to  
put the 32-bit binary in one dir, the 64-bit one in another, and  
direct the client to the right spot.

Thanks,  
Eric P.

---

<div class="post-metadata">

**Author:** ![epasquier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/2bfe46/32.png) [@epasquier](https://www.ruby-forum.com/u/epasquier)\
**Post date:** [September 3, 2008, 3:03am UTC](https://www.ruby-forum.com/t/can-a-ruby-program-determine-whether-its-running-on-a-32-bit-or-64-bit-system/147552/2 "2008-09-03T03:03:30Z")

</div>

On Wednesday 03 September 2008 02:39:37 Eric P. wrote:

> I can’t go by RUBY\_PLATFORM – I’m setting up a new 32-bit Linux box,  
> and RUBY\_PLATFORM is set to “i686-linux”.  
> Well, i?86 means it is 32bit.  
> 64-bit x86 system would have ‘x86\_64-linux’.

Jan

---

<div class="post-metadata">

**Author:** ![epasquier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/2bfe46/32.png) [@epasquier](https://www.ruby-forum.com/u/epasquier)\
**Post date:** [September 3, 2008, 3:56am UTC](https://www.ruby-forum.com/t/can-a-ruby-program-determine-whether-its-running-on-a-32-bit-or-64-bit-system/147552/3 "2008-09-03T03:56:48Z")

</div>

Eric P. wrote:

> Can a Ruby program determine whether  
> it’s running on a 32-bit or 64-bit system?

Yes. Look at the result of calling the ‘size’ method on a Fixnum; it  
will be 4 on 32-bit machines, and 8 on 64-bit machines.

> > 0.size  
> > =\> 4

---

<div class="post-metadata">

**Author:** ![epasquier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/2bfe46/32.png) [@epasquier](https://www.ruby-forum.com/u/epasquier)\
**Post date:** [September 4, 2008, 12:10am UTC](https://www.ruby-forum.com/t/can-a-ruby-program-determine-whether-its-running-on-a-32-bit-or-64-bit-system/147552/4 "2008-09-04T00:10:10Z")

</div>

I got 4 on 64bit Windows Server. That doesn’t mean that it depends if it  
was  
built on 64bit or 32bit, I mean ruby core.

2008/9/2 Suraj K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![epasquier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/2bfe46/32.png) [@epasquier](https://www.ruby-forum.com/u/epasquier)\
**Post date:** [September 4, 2008, 1:50am UTC](https://www.ruby-forum.com/t/can-a-ruby-program-determine-whether-its-running-on-a-32-bit-or-64-bit-system/147552/5 "2008-09-04T01:50:45Z")

</div>

Le 3 septembre 2008 à 02:42, Eric P. a écrit :

> I can’t go by RUBY\_PLATFORM – I’m setting up a new 32-bit Linux box,  
> and RUBY\_PLATFORM is set to “i686-linux”.

Pack has a support for native size :

> > RUBY\_PLATFORM  
> > =\> “i386-freebsd6”
> 
> > [-1].pack(‘l!’).length  
> > =\> 4

While…

> > RUBY\_PLATFORM  
> > =\> “amd64-freebsd7”
> 
> > [-1].pack(‘l!’).length  
> > =\> 8

(From the Pickaxe : ‘Any of the directives “sSiIlL” may be followed by  
an underscore (\_) or bang (!) to use the underlying platform’s native  
size for the specified type’)

Fred

---

<div class="post-metadata">

**Author:** ![epasquier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/2bfe46/32.png) [@epasquier](https://www.ruby-forum.com/u/epasquier)\
**Post date:** [September 4, 2008, 3:33pm UTC](https://www.ruby-forum.com/t/can-a-ruby-program-determine-whether-its-running-on-a-32-bit-or-64-bit-system/147552/6 "2008-09-04T15:33:07Z")

</div>

Suraj K. wrote:

> Eric P. wrote:
> 
> > Can a Ruby program determine whether  
> > it’s running on a 32-bit or 64-bit system?
> 
> Yes. Look at the result of calling the ‘size’ method on a Fixnum; it  
> will be 4 on 32-bit machines, and 8 on 64-bit machines.
> 
> > > 0.size  
> > > =\> 4

On my 32 bit machine I get this:  
p 0.size  
=\> 8

p [-1].pack(‘l!’).length  
=\> 4

I am not sure why, but there it is, fyi.
