Reputation: 9899
In Ruby script, I want to get OS information, not only Linux, but also 32bit or 64bit.
That's because my program will run on multiple Linux platform. It calls a third part tool, the tool has sub-folder: lin32
, lin64
, I need to call proper version based on OS info.
Upvotes: 3
Views: 3991
Reputation: 3869
In Ruby you can use RUBY_PLATFORM
constant. This constant produces a base name of your OS and kernel bits level.
E.g. in irb:
1.9.3-p392 :001 > RUBY_PLATFORM
=> "x86_64-linux" - Linux based OS with 64-bit
=> "i686-linux" - Linux based OS with 32-bit
Upvotes: 6
Reputation: 33536
Since you refer to linux, use uname -m
as described here: How to determine whether a given Linux is 32 bit or 64 bit?
ignore the bottom "CPU" part. because you want to run a program, you want the kernel architecture:
irb:(main):001:0> `uname -m`
=> "x86_64"
x86_64 ==> 64-bit kernel
i686 ==> 32-bit kernel
Upvotes: 0
Reputation: 1399
You can use the RUBY_PLATFORM constant
irb(main):001:0> RUBY_PLATFORM
=> "i686-linux"
Upvotes: 0
Reputation: 4440
Also, you can try someth like:
ver = `getconf LONG_BIT`
or
ver = `arch`
Upvotes: 2